[Qt-interest] Simple question regarding the threads documentation
Patric
userqt at gmail.com
Thu Jun 18 12:36:11 CEST 2009
I see what you mean... but I'm connecting one object of type MainWindow to another of type TestManager.
testManager.moveToThread(MyThread::myThread);
connect(this, SIGNAL(mainSignal()), &testManager, SLOT(onMainSignal()));
connect(&testManager, SIGNAL(threadSignal()), this, SLOT(onThreadSignal()));
And I'm just moving the testManager object to MyThread, and am connecting the MainWindow object to the TestManager object. And vice versa. And it's working.
Regards,
Patric
----- Original Message -----
From: Jesús Fernández Prieto
To: Patric
Cc: qt-interest at trolltech.com
Sent: Thursday, June 18, 2009 11:44 AM
Subject: Re: [Qt-interest] Simple question regarding the threads documentation
Hi!
Yes, it really works in this case, because you are connecting an object with a QThread object. But the QThread object is not in the new thread.
The new thread is alive in the QThread::run method execution.
If there's a method MyThread::newMethod() and you call it from the main thread the method will be executed in the main thread.
2009/6/18 Patric <userqt at gmail.com>
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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
__________ 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/22601a4d/attachment.html
More information about the Qt-interest-old
mailing list