Stoped thread still receives signals
I 've a 2 classes that extend Qthread, connected by signlas/slots. The first one sends signals to the latter. The second class lives for 10 cycles, then the run() returns. However, even if the isRunning() is false, the class still reacts to the signals!
Where am i wrong?
Thank you :)
It doesn't matter if the run() function has returned, your QThread subclass still is alive and living in the main thread (thus having a working eventloop).
On a side note, consider NOT to subclass from QThread and instead to use the worker object approach which is considered best practise for QThread. For more information follow these links:
"You're doing it wrong":http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/
"best practise for QThread":http://qt-project.org/wiki/QThreads_general_usage
"doc note in QThread reference":http://qt-project.org/doc/qt-4.8/QThread.html#notes
Ok thank you. So i need to notify this to main thread to stop the interaction....
After using QObject::connect() for your signal and slot..... it is better to use QObject::disconnect()
I think it is a safer and cleaner way. I use it most of the time. :)
[quote author="lor.lucignano" date="1354629242"]Ok thank you. So i need to notify this to main thread to stop the interaction....
Just emit a signal right before the run function terminates. Catch the signal somewhere where you have access to the QThread object and disconnect it.
But seriously you should not subclass QThread unless you absolutely have to.