Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()

like image 898
Nir Cig Avatar asked Nov 05 '22 04:11

Nir Cig


2 Answers

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

like image 126
Phil Hannent Avatar answered Nov 09 '22 12:11

Phil Hannent


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 ^^

like image 41
Alexander Nassian Avatar answered Nov 09 '22 11:11

Alexander Nassian