[Qt-interest] Simple question regarding the threads documentation

Jesús Fernández Prieto jsfdez at gmail.com
Thu Jun 18 10:44:42 CEST 2009


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<http://doc.trolltech.com/4.5/timers.html>and the network
> module <http://doc.trolltech.com/4.5/qtnetwork.html>. For example, you
> cannot start a timer or connect a socket in a thread that is not the object's
> thread <http://doc.trolltech.com/4.5/qobject.html#thread>.
>
> Especially the last words
>
> "or connect a socket in a thread that is not the object's thread<http://doc.trolltech.com/4.5/qobject.html#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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090618/cc8995d7/attachment.html 


More information about the Qt-interest-old mailing list