[Qt-interest] Simple question regarding the threads documentation

Patric userqt at gmail.com
Thu Jun 18 10:35:47 CEST 2009


Hi all. I have a newby question here. 
I was reading the Thread support documentation, and found out this 

Event driven objects may only be used in a single thread. Specifically, this applies to the timer mechanism and the network module. For example, you cannot start a timer or connect a socket in a thread that is not the object's thread.

Especially the last words

"or connect a socket in a thread that is not the object's thread."

I didn't understood this. 
So I tested it with the following situation : 

Classes MainWindow, MyThread and TestManager. 
In MainWindow there is a signal that calls a slot in TestManager. In TestManager there is a signal that calls a slot in MainWindow. I put an instance ofTestManager in MainWindow. 
In MainWIndow's constructor, I do the following : 

testManager.moveToThread(MyThread::myThread);

connect(this, SIGNAL(mainSignal()), &testManager, SLOT(onMainSignal()));
connect(&testManager, SIGNAL(threadSignal()), this, SLOT(onThreadSignal()));





And it works. Here the slot is not in the thread that creates the connection. The following also works : 





connect(this, SIGNAL(mainSignal()), &testManager, SLOT(onMainSignal()));
testManager.moveToThread(MyThread::myThread);
connect(&testManager, SIGNAL(threadSignal()), this, SLOT(onThreadSignal()));



and 



connect(this, SIGNAL(mainSignal()), &testManager, SLOT(onMainSignal()));
connect(&testManager, SIGNAL(threadSignal()), this, SLOT(onThreadSignal()));

testManager.moveToThread(MyThread::myThread);



Just wondering. 



Patric 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4098 (20090522) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090618/7bbb2694/attachment.html 


More information about the Qt-interest-old mailing list