After updating Qt 4.7.2 to Qt 4.8.2 I've noticed something strange in QThread behavior. It seems like isRunning returns true even when the thread is finished (the finished signal is already emitted). The following code shows the issue: it prints "the thread is finished, isRunning = true" from the handleThreadFinished slot connected to the thread's finished signal. I've encountered a few new bugs in my application because of this change. Was this behavior intended?

Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QTimer>
  3. #include <QThread>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class MyThread: public QThread
  9. {
  10. protected:
  11. virtual void run()
  12. {
  13. QTimer::singleShot(1000, this, SLOT(quit()));
  14. exec();
  15. //QThread::run();
  16. }
  17. };
  18.  
  19. class Test: public QObject
  20. {
  21. Q_OBJECT
  22.  
  23. public slots:
  24. void run()
  25. {
  26. t = new MyThread;
  27. connect(t, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
  28. t->start();
  29. }
  30.  
  31. private slots:
  32. void handleThreadFinished()
  33. {
  34. cout << "the thread is finished, isRunning = " << (t->isRunning() ? "true" : "false") << endl;
  35. t->deleteLater();
  36. }
  37.  
  38. private:
  39. MyThread *t;
  40. };
  41.  
  42. int main(int argc, char *argv[])
  43. {
  44. QCoreApplication a(argc, argv);
  45. Test test;
  46. QTimer::singleShot(0, &test, SLOT(run()));
  47. return a.exec();
  48. }
  49.  
  50. #include "main.moc"
To copy to clipboard, switch view to plain text mode