开发者

Integrating a Qt widget in a .NET (WPF) application

I have a working Qt widget which I want to show in a .NET application. The application is using WPF and I want to embed that widget somewhere in the UI.

What is the recommended way to embed a Qt widget in a WPF application? should I use C++/CLI and pass the HWND to WPF, or just use ActiveQt? I'm concerned about the Qt event mechanism, since no one will be calling QApplication::exec(开发者_开发知识库)


What you need to do is use the QAxServer to turn your widget into a COM object:

http://developer.qt.nokia.com/doc/qt-4.8/activeqt-server.html

Which will turn your object into a COM object. You should then be able to reference it as such. However this is really not a normal practice with working across 3 technologies (Qt, COM, WPF).

For communicating back and forth you'll need to setup bindings:

http://developer.qt.nokia.com/doc/qt-4.8/qaxbindable.html


Is ActiveQt still actively supported?! Just wondering ...

In one of my projects I had a similar problem. I solved it by wrapping the Qt initialization (QApplication and ::exec()) in a function that I call via PInvoke and then just use the QWidgets (QWidget::getDC() returns the native handle).

It's not the cleanest way, but combining Qt, COM and WPF is not the cleanest thing at all ^^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜