PDA

View Full Version : Multiple start() on same QThread Object



mdecandia
13th April 2007, 16:53
Hi all,
can I run multiple start() method on same QThread object ?

Simple example follows:



int main(int argc, char *argv[]){
QCoreApplication app(argc,argv);
threadHandler *TH=new threadHandler();
TH.start()
TH.start()

return app.exec();
}

This code executes the two run() methods as two serial executions.
Is this correct? Do you have experience in this?

Thanks,
Michele

guilugi
13th April 2007, 16:57
No, only the first call will be effective.
If you call start() a second time while the thread is running, it will do nothing !

http://doc.trolltech.com/4.2/qthread.html#start

Brandybuck
13th April 2007, 19:35
You can use the same class, but two objects, to get two threads. Myabe this is what you want.

eelik
3rd November 2009, 08:53
No, only the first call will be effective.
If you call start() a second time while the thread is running, it will do nothing !

http://doc.trolltech.com/4.2/qthread.html#start

Am I correct if I suppose this means that start() can be called several times IF the run() method has returned between the calls?

wysota
3rd November 2009, 09:14
Yes, you can start the thread again when it has already finished.