I have a small worker thread:

Qt Code:
  1. class ReloadDirectoryThread : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. ReloadDirectoryThread()
  6. : QThread() {
  7. };
  8.  
  9. ~ReloadDirectoryThread() {
  10. };
  11.  
  12. void run() {
  13. exec();
  14. };
  15.  
  16. public slots:
  17. void importImage(int row, QString filePath);
  18. signals:
  19. void imageImported(int row, QIcon* icon);
  20. };
To copy to clipboard, switch view to plain text mode 

Its task is to open Images pointed to by filePath, convert them into a QIcon and emit each new Icon:

Qt Code:
  1. void ReloadDirectoryThread::importImage(int row, QString filePath)
  2. {
  3. QIcon* icon = new QIcon(QPixmap(filePath));
  4. emit imageImported(row, icon);
  5. }
To copy to clipboard, switch view to plain text mode 

The thread will be started from the main-application thread:

Qt Code:
  1. { ...
  2. reloadDirectoryThread = new ReloadDirectoryThread;
  3.  
  4. connect(this, SIGNAL(importImage(int,QString)),
  5. reloadDirectoryThread, SLOT(importImage(int,QString)), Qt::QueuedConnection);
  6.  
  7. connect(reloadDirectoryThread, SIGNAL(imageImported(int,QIcon*)),
  8. this, SLOT(imageImported(int,QIcon*)), Qt::QueuedConnection);
  9.  
  10. reloadDirectoryThread->moveToThread(reloadDirectoryThread);
  11. reloadDirectoryThread->start();
  12. ...}
To copy to clipboard, switch view to plain text mode 


The Thread should be shut down when closing the app:

Qt Code:
  1. {...
  2. reloadDirectoryThread->quit();
  3. reloadDirectoryThread->wait(3000);
  4. delete reloadDirectoryThread;
  5. ...}
To copy to clipboard, switch view to plain text mode 

This will tell the thread to quit its eventLoop and waits at most 3 seconds for the thread to finish. At this time all "importImage"-signals are already posted into the event queue.

My problem is that the worker-thread always completes all messages (what in fact lasts more than three seconds) until the Thread Object can be deleted safely.

Any ideas what's going wrong ? Why does the thread not stop executing events from the eventqueue when calling quit() ?

.. frank