[Qt-interest] Qt Signal slot mechanism with QThread
John McClurkin
jwm at nei.nih.gov
Tue Jan 19 19:59:06 CET 2010
raJkumar subbarayan wrote:
> Hi All,
> I read about QThread behavior along with signal slot mechanism
> from http://doc.trolltech.com/4.6/threads-qobject.html#signals-and-slots-across-threads and
> few more places.
> I have couple of questions regarding the article.
> 1)Is it always good to specify whether the connection is Direct
> Connection
> <http://doc.trolltech.com/4.6/qt.html#ConnectionType-enum> or Queued
> Connection
> <http://doc.trolltech.com/4.6/qt.html#ConnectionType-enum> in QObject::connect
> function?
> In case of direct connection the slot is
> called immediately after emit is encountered.
>
> But in case signal emitted thread and object whose slot is
> called is in different thread leads to immediately putting the
> slot's thread to wait and execution of slot in it's thread
> happens, make sure the slot is reentrant in this case.
>
Whether it is good or not is a value judgement, not a programing issue.
It is necessary only if you want to guarantee a certain behavior. Qt is
pretty good at figuring out what type of connection to use.
> 2)I find difficulties understanding how Qt selects one of above
> connection in case the parameter is left blank, can any one explain ?
The default connection type is Qt::AutoConnection.
From the documentation on Qt::AutoConnection
"if the signal is emitted from the thread in which the receiving object
lives,
the slot is invoked directly, as with Qt::DirectConnection;
otherwise the signal is queued, as with Qt::QueuedConnection."
Is this explanation not clear to you?
More information about the Qt-interest-old
mailing list