Hello everyone,

I tried code similar to the following (i shortened it a bit):
Qt Code:
  1. class WorkerThread : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. ~WorkerThread();
  6. protected:
  7. void run();
  8. private slots:
  9. void update();
  10. private:
  11. volatile bool m_isInterrupted;
  12. };
  13. WorkerThread::~Workerthread()
  14. {
  15. m_isInterrupted = true;
  16. wait();
  17. }
  18. void WorkerThread::run()
  19. {
  20. QTimer * timer = new QTimer(this);
  21. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  22. timer->start(80);
  23. exec();
  24. }
  25. void WorkerThread::update()
  26. {
  27. if(m_isInterrupted)
  28. {
  29. quit();
  30. }
  31. //do something
  32. }
To copy to clipboard, switch view to plain text mode 

The wait() call is needed to prevent the main thread from deleting the workerThread object, while it is still running...

Note: I tested it with slightly different code, so I'm not 100% sure if the following statements are accurate, but I think so:
When closing the application, the process does not terminate and the quit() method is never called, which I verified by debugging.

I think this happens because when the mainthread calls wait() somehow the workingthread's event queue is not dispatched anymore, but I don't understand why, I thought the workingthread has a different evene queue.

It would be nice if you can explain me, why this happens and how I can fix it.
Alternative solutions for my problem would be nice, too!

Thanks for help in advance!