[Qt-interest] Confused by dev-net wiki article: inter-thread sig-slot connections
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Fri Jun 17 13:45:14 CEST 2011
Hi all,
I was going through the new docs on dev net on Qthreads
(http://developer.qt.nokia.com/doc/qt-4.7/qthread.html) to see if our
discussions on the often debated/popular topic on threads is covered
or not. :)
There's a good wiki article pointed to by the "Notes provided by the
Qt Community" which helps in clarifying the common misconceptions
about using QThread
(http://developer.qt.nokia.com/wiki/Threads_Events_QObjects).
All was well with the wiki article, till I reached the section
"Signals and slots across threads". The article shows the following
example (see the 1st example shown):
class Thread : public QThread
{
Q_OBJECT
signals:
void aSignal();
protected:
void run() {
emit aSignal();
}
};
/* ... */
Thread thread;
Object obj;
QObject::connect(&thread, SIGNAL(aSignal()), &obj, SLOT(aSlot()));
thread.start();
...
It then goes on to say that the connection made above, would be a
'queued' connection and NOT 'direct'!
I remember (I think Thiago had mentioned it), that Qt will compare the
thread affinity of the object that emitted the signal with that of the
object that has the receiving slot. If they're same, a direct
connection would be made.
But from the wiki article, it seems that Qt is comparing the thread
context _when_ the signal is emitted with the receivers' thread
affinity and NOT the emitter's thread affinity.
So what is the correct answer - in the above example is it a direct or
queued connection?
I'm confused again! :(
Thanks,
-mandeep
More information about the Qt-interest-old
mailing list