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?
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?
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)
So if I add it to destructor I must always call "delete thread" when stopping thread?
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)
@Edit
Ok, problem is solved.
Thanks again wysota
Last edited by Macok; 7th February 2009 at 18:03.
Bookmarks