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 ^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With