[Development] Trigger Qt event loop from external message loop

Sze Howe Koh szehowe.koh at gmail.com
Fri Dec 20 01:50:05 CET 2013


On 20 December 2013 04:52, Kuba Ober <kuba at mareimbrium.org> wrote:
> Is this supported on all platforms now? IIRC it did not work OS X last time I tried, but yes,
> it did work great on Windows.
>
> — Kuba

The Cocoa framework mandates that all GUI-related operations must be
done in the first thread in a process [1]. That's why this technique
cannot work on OS X. I believe it was possible with Carbon apps, but
not Cocoa apps.


Regards,
Sze-Howe

[1] http://www.cocoabuilder.com/archive/cocoa/315103-why-is-the-threading-and-ui-updating-designed-to-be-done-only-on-main-thread.html


> On Dec 14, 2013, at 3:25 PM, Roland Winklmeier <roland.m.winklmeier at gmail.com> wrote:
>
>> Thanks very much Olivier and Thiago!
>> That works brilliant.
>>
>> No idea why I forgot that QThread must not be used. But its of course
>> obvious. I made a quick setup with native threads (std::thread is
>> unfortunately not supported by VC2010) and it works perfectly now.
>>
>> In case someone is interested:
>> - - I added a additional shared library spawning a thread and links the
>> actual plugin during runtime with LoadLibrary/dlopen. No Qt stuff in here.
>> - - Second shared library creates QApplication object and runs its
>> exec() loop.
>>
>> Cheers Roland
>>
>> Am 14.12.2013 19:23, schrieb Thiago Macieira:
>>> On sábado, 14 de dezembro de 2013 12:42:32, Roland Winklmeier
>>> wrote:
>>>> n qthread_win.cpp QThreadPrivate::start -> void
>>>> QThreadPrivate::createEventDispatcher(QThreadData *data) {
>>>> QEventDispatcherWin32 *theEventDispatcher = new
>>>> QEventDispatcherWin32;
>>>> data->eventDispatcher.storeRelease(theEventDispatcher);
>>>> theEventDispatcher->startingUp(); }
>>>
>>> You must not use QThread.
>>>
>>> You need to start your thread before using any QObject-derived
>>> classes. Once you're there, instantiate the QApplication



More information about the Development mailing list