[Qt-interest] Qt Signal slot mechanism with QThread
raJkumar subbarayan
yesraaj at gmail.com
Wed Jan 20 04:20:26 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-threadsand
> > 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.
> >
> Thanks John McClurkin.
> 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?
>
I am looking for much more information, what does the term "thread from
which the signal is emitted" does that look for where the object whose
signal is emitted live or the where the emit signal line is encountered?
Just changing the signaling object to other thread(using moveToThread) will
make any change in connection type? Where the connection type is established
is it runtime or at compile time or both please explain how it is done?
Is my interpretation correct about the following line?
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.
Thanks,
Raj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100120/d8e3bfec/attachment.html
More information about the Qt-interest-old
mailing list