[Qt-interest] QThread Question
Bradley T. Hughes
bradley.hughes at nokia.com
Thu Aug 6 13:43:49 CEST 2009
Donal O'Connor wrote:
> Sorry Sean, never noticed the iff :)
>
> So indeed, nothing is executed in the worker thread since no moveToThread
> done anywhere in this code. So that means that the connection type (auto
> default) will result in a direct connection since the QThread object was
> created in the GUI thread and does not belong to the QThread object thread.
Correct, QThread's affinity will be to the GUI thread (since that is where
it was created). This means all AutoConnections to the QThread subclass's
slots will be run in the main thread.
> I think I've got it right this time :)
You do ;)
> Thanks for your time.
A small suggestion: change the class that you're working on to inherit
directly from QObject instead. Then instantiate it and a QThread, move your
object to the newly created (but completely disjoint) thread, and enjoy.
Essentially, something like this (overly simplified for the author's
convenience :P):
MyObject *obj = new MyObject(...);
QThread *thread = new QThread(...);
connect(...);
obj->moveToThread(thread);
thread->start();
--
Bradley T. Hughes (Nokia-D-Qt/Oslo), bradley.hughes at nokia.com
Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
More information about the Qt-interest-old
mailing list