[Development] Trigger Qt event loop from external message loop

Roland Winklmeier roland.m.winklmeier at gmail.com
Sat Dec 14 12:42:32 CET 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 14.12.2013 02:16, schrieb Thiago Macieira:
> On sábado, 14 de dezembro de 2013 00:45:20, Roland Winklmeier 
> wrote:
>> 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.
> 
> You have to do that.
> 
> Use another thread then. All of your proposed solutions in your 
> email will run into trouble sooner or later.
> 

Thiago,

thanks for that hint. I changed the plugin to start its own thread. In
this thread I create the QApplication, the dialog and call
QApplication::exec(). Everything fine and clean now besides the
following issue:

In qthread_win.cpp
QThreadPrivate::start ->
void QThreadPrivate::createEventDispatcher(QThreadData *data)
{
    QEventDispatcherWin32 *theEventDispatcher = new QEventDispatcherWin32;
    data->eventDispatcher.storeRelease(theEventDispatcher);
    theEventDispatcher->startingUp();
}

but I expected to have a pointer to QWindowsGuiEventDispatcher which
is a subclass from QEventDispatcherWin32 and located in the QPA plugin.
If I run the standalone application without threading, the event
dispatcher is created in qapplication_qpa.cpp:

void QApplicationPrivate::createEventDispatcher()
{
    QGuiApplicationPrivate::createEventDispatcher();
}
- ->
void QGuiApplicationPrivate::createEventDispatcher()
{
    Q_ASSERT(!eventDispatcher);

    if (platform_integration == 0)
        createPlatformIntegration();

    // The platform integration should not mess with the event dispatcher
    Q_ASSERT(!eventDispatcher);

    // Creates a QWindowsGuiEventDispatcher on windows
    eventDispatcher = platform_integration->createEventDispatcher();
}

So if I run the application in its own thread, QThread creates its
custom event dispatcher, hence no QWindowsGuiEventDispatcher object is
created later in QApplication. But QEventDispatcherWin32 is not
handling window system messages in its sendPostedEvents() method.
Thats why the application does not do anything when I click on buttons.

Does this make sense and could it be fixed, that I get the same event
dispatcher in both cases?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSrEQoAAoJEI9ELizP04ba2CAH+QHoxVVbL9UJOud0vpEw5zwj
catLBSIvz/r4vAwrt6iDu/FHbrZ6aobWX0t1HhdGzaiT90OMjBdbPZNskvd5+gwA
PyO8GTgUXRPF58GCgY6dtW2X7PBd1S1Am3MXWAUeLjES1olZ0CRVDeuJRVgCp+No
o57FcI7vKACekzNitDBgn/hkclcor/oOinRzY8R1qEkyc8HUURD2kG6FhEiZfaQS
zFzom7qJ+3IXJ+9vpHgmobPQJil3rHApgfWQIZ47rdcsjV5mqnm+y85K92qWLNeL
FXTjYrZwxooFQhBWGl05MnM6zM9YVuW1k02hYMefSwH9iNdetSayOhPYkvJW4Yk=
=Xh1g
-----END PGP SIGNATURE-----

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