user2259419
user2259419

Reputation: 61

Using Qt user interface in a host application

I am extending a commercial application, running on Windows. It can be extended by plug-ins, which for this application are ordinary DLLs. Free functions exported from plug-in DLLs can be hooked to the host application UI, which forms commands, and these commands can be used based on user interaction with host application UI. Additionally, it looks like the plug-ins run in the same thread as the host application, or at least all the plug-ins run in the same thread.

It is also possible to write user interface for these plug-ins. As host application was ported from another platform, the user interface is using windows as a main container for main window and dialog panels, but the window content and its controls are owner-drawn.

Example plug-ins, shipped with the application, use the old fashioned way of writing Windows user interface - they have a standard resource file, standard window procedure, standard dialog box procedure, standard event loop using GetMessage(), TranslateMessage(), DispatchMessage().

Windows in these example plug-ins are created in one of the plug-in DLL functions. The event loop is also running there.

In those examples it is possible to create modal and modeless windows and the integration seems to be working fine. Just a visual style is 'a bit' mixed.

It is even possible, or better, due to simple example design it is not disallowed to invoke the command multiple times, which opens multiple windows of the same kind and still it looks like everything works.

I would like to use Qt for the UI of my plug-ins. When I do it, however, the host user interface just stops reacting. It is not even repainting.

Initially I used QApplication.exec(), which blocked everything, but soon enough I learned not to call it. Instead I keep the original message loop from the example application and inside it I call QApplication.processEvent(). But it still does not work.

I am wondering, what is happening there, when Qt application behaves so differently? Is Qt blocking some messages or what is going on?

I also tried to integrate the QWinWidget, but it has the similar effect.

Upvotes: 0

Views: 554

Answers (3)

Uga Buga
Uga Buga

Reputation: 1784

One solution that comes into my mind is to invoke the plugins in separate threads using QtConcurrent::run(). It returns QFuture object which could be used for waiting the thread with QFuture::waitForFinished() and thus using the Qt application's event loop. The template parameter of QFuture can be used to return a result from the function. Hope this helps

Upvotes: 1

c-smile
c-smile

Reputation: 27470

You don't need your own message pumps (GetMessage(), TranslateMessage(), DispatchMessage() loop) as host application is running its own already.

It appears as QWinWidget is way to go for you if you really want to add Qt to that mix.

You also can try my htmlayout or sciter engine so your UI will be defined as HTML/CSS.

Upvotes: 0

phyatt
phyatt

Reputation: 19152

I would interact with the standard event loop elements and messages in a QThread and then use signals and slots to interact with the Qt GUI. The event loop system of Qt may resemble the event loop from other operating systems, but it also does a number of things for memory management and various other things that are unique to itself.

The documentation of the Event System may shed more light as to why it is blocking the loops from the plugins/dlls you are using:

http://qt-project.org/doc/qt-4.8/eventsandfilters.html

Hope that helps.

Upvotes: 0

Related Questions