Hello, I'm trying to implement a simple gui with a worker thread using Qt 4.1.1

My gui is managed in the QApplication's event loop. The worker thread also has its event loop.

The worker thread starts some work when the GUI emits a defined signal (Qt::QueuedConnection because signal->slot are in different threads).

(of course,) the worker thread interrupts its event loop to do its job. The worker thread emits signals back to the gui thread to report progress, and that on a regular basis (to display a nice QProgressBar). The worker thread doesn't return to it's event loop until the job is finished.

The problem: my GUI thread does not process any event (coming from the worker thread) until the worker thread finishes its job and returns to its event loop.

Same problem in the other direction. When the user quits the programm, the GUI emits a signal ("request finish") to the worker thread so that it finishes, the GUI then wait() for the worker thread's termination. But the worker thread never handles the "request finish" signal until the GUI thread returns to its event loop. The code below illustrates that and locks both threads.

Qt Code:
  1. // GUI code, this is a slot; auto connected by moc.
  2. void on_exitButon_clicked(void) {
  3. QTimer::singleShot(0, workerThread, SLOT(stopThread(void)));
  4. workerThread->wait();
  5. close();
  6. }
To copy to clipboard, switch view to plain text mode 

This is really strange, I already worked with threads, but never in Qt. It seems here that when a thread blocks the other are not scheduled.

Thanks for your time!