Hi,

I want to inform an object when a thread has finished running. However, I cannot get the thread to exit properly. I have the following code:

Processor.cpp

Qt Code:
  1. thread = new QThread;
  2. tw = new ThreadWorker;
  3. connect(tw, SIGNAL(updateStatus(QString)), this, SLOT(statusUpdate(QString)));
  4. tw->doSetup(thread, strDic);
  5. tw->moveToThread(thread);
  6. thread->start();
  7.  
  8. while(thread->isRunning())
  9. {
  10. }
  11.  
  12. qDebug() << "Thread Finished";
To copy to clipboard, switch view to plain text mode 


ThreadWorker.cpp

Qt Code:
  1. void ThreadWorker::doSetup(QThread *thread, const string &path)
  2. {
  3. _strPath = path;
  4. connect(thread, SIGNAL(started()), this, SLOT(run()));
  5. connect(this, SIGNAL(finished()), thread, SLOT(quit())); //tried terminate() also
  6. }
  7.  
  8.  
  9. void ThreadWorker::run()
  10. {
  11. DirectorySearch dicSearch;
  12. vector<string> vecFileList = dicSearch.getFileList(_strPath);
  13. emit updateStatus("Directory Fetched");
  14. emit finished();
  15. }
To copy to clipboard, switch view to plain text mode 

The quit() slot does not seem to stop the thread (QThread::isFinished never returns true). Can someone guide me in the right direction?

Thanks in advance