[Development] Trigger Qt event loop from external message loop

Roland Winklmeier roland.m.winklmeier at gmail.com
Sat Dec 14 00:45:20 CET 2013


Hi there,

I'm working on an application using Qt5 for its window framework. The
requirement for this application is to run standalone and as a plugin
for a native application.
While the case standalone application is easy, I'm struggling a bit with
the plugin part. I have the following in mind:

The plugin is loaded by a native application as a plugin. After the
plugin is attached as a shared library a QApplication object is created
and a dialog is shown, when the user selects it from the menu. Since I
cannot run Qt's event loop with QApplication::exec() - I dont want the
plugin to block the parent application - I try to trigger the event loop
externally. The two options I have are:

qApp->sendPostedEvents();
or
qApp->processEvents();

The second one is not a good idea, since it calls PeekMessage(...,
PM_REMOVE) which removes any message. Even that targeted for the parent
application -> not a good idea.
qApp->sendPostedEvents() on the other hand does send everything except
window system messages.
qwindowsysteminterface.cpp sais the following about this topic:
"The platform plugins call the various functions to notify about events.
The events are queued until sendWindowSystemEvents() is called by the
event dispatcher." So I would need to call sendWindowSystemEvents()
before. This can be done by calling
QEventDispatcherWin32::sendPostedEvents() which is protected and part of
the private headers. Even though it is virtual, its base class
QAbstractEventDispatcher does not have such a method. During runtime a
QWindowsGuiEventDispatcher object is allocated and its virtual method
sendPostedEvents() is used. This is what I would need.

Now I'm stuck. Would it be possible to just add a public method in
QAbstractEventDispatcher, e.g.
QAbstractEventDispatcher::sendPostedGuiEvents() or anything else? Any
other ideas?

I know this is a special case, but I think its worth to solve it.

Summary - the following use cases work:
- QApplication::processEvent() for long running methods (in case all
messages are really targeted to your Qt application).
- QApplication::sendPostedEvents() which sends every core application
events.

The following use case does not work up to now:
- Qt application has a parent with its own message loop. Window system
events get stuck and are never sent. (besides some exceptions, e.g.
resizing, since it triggers flushWindowSystemEvents() ).

Any would be appreciated!

Thanks,
Roland

PS: I've raised https://bugreports.qt-project.org/browse/QTBUG-32962
some month ago. Yesterday I tried it with 5.2.0 and forgot, I had a
local workaround in place. So contrary to what is written, it is not
fixed in 5.2.0

---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com




More information about the Development mailing list