PDA

View Full Version : [QThread] Function calling after thread.stop()



Macok
6th February 2009, 22:28
I'd like my thread to do something after quiting, when stop method is called.
For example I have opened file in my thread, and I want to close it when thread is stopping.
How to do it?

wysota
7th February 2009, 00:00
The best way would be to do the cleanup before QThread::run() returns. If it is not possible then you can do the cleanup in the QThread object destructor (just remember it will be ran in the context of the thread that created the object, not the thread created by the object).

Macok
7th February 2009, 11:17
So if I add it to destructor I must always call "delete thread" when stopping thread?

wysota
7th February 2009, 12:33
No, it only means the cleanup wil not be performed by the thread itself but the thread that created the QThread object. Read about thread affinity in Qt Reference Manual.

Macok
7th February 2009, 13:33
@Edit
Ok, problem is solved.
Thanks again wysota :)