Quit and delete thread
-
wrote on 3 Aug 2011, 11:10 last edited by
Hellow, i have one problem:
I have many threads and when i finished thread i want to delete it, but if i write
@void myThread::getDeleteAndQuit() //slot
{
this->exit(0);
delete this;
}@
and coll it that i have error, why?
I dont use some slots and everything should be done linearly
I have no way of storing pointers to the threads
Advance many thanks for your help! -
wrote on 3 Aug 2011, 11:14 last edited by
You delete your self. I assume, you do it inside run, right? but run is only a method, called by QThread methods. after the delete, the call stack returns to the calling function (e.g. run) and the to the caller of run, which might access members of QThread, which you deleted.
EDIT: exit justs exits, the event loop
-
wrote on 3 Aug 2011, 11:45 last edited by
How can i edit it?
-
wrote on 3 Aug 2011, 12:21 last edited by
bq. I assume, you do it inside run, right?
No, this slot i called from other slot, which causes signal
-
wrote on 3 Aug 2011, 12:32 last edited by
Now I get confused. Who calls what when?
exit will cause the event loop to stop, but not synchronously. The thread has not finished then.
perhaps the wait trick helps you:@
void myThread::getDeleteAndQuit() //slot
{
this->exit(0);
this->wait(); // <-- wits till the thread has exited
deleteLater(); // <-- ensures that it will be deleted later when the (main?) event loop executes again
}
@ -
wrote on 3 Aug 2011, 13:56 last edited by
It is help me!
Thank you for your help!
1/7