Threadweaver or QThread?

Andreas Pakulat apaku at
Thu Sep 27 09:39:23 BST 2007

On 27.09.07 08:56:01, Mirko Boehm wrote:
> both will not work directly: Neither a QThread nor a ThreadWeaver job
> can open a dialog, only the main thread can do this.

Yeah, I know that part :)

> * make a slot in the parent widget of the dialog in the main thread that
> shows the dialog.
> * connect that slot to a signal send from the job, asynchronously.
> * have the job emit the signal and then enter a wait condition.
> * have the slot in the main widget show the dialog, then set the result
> on the job. the method that sets the result can wake the wait condition
> at the end.

Ok, I'll do it with events instead of signals/slots because I have to
transport some data from the worker thread to the GUI thread (yes I
could do that as well via the signals, but I find it easier this way)

> If you have to perform such operations in many different ways, I suggest
> a command pattern implementation.
> The described approach works both from within a ThreadWeaver job (which
> is a QObject), and from within a QThread::run method. Make sure to
> explicitly create the connection asynchronously, or to otherwise be
> sure the slot is not called from the second thread.

Thats mainly what I wanted to know :) Wasn't sure if I can treat a
threadweaver job like a plain QThread in this regard.


You fill a much-needed gap.

More information about the kde-core-devel mailing list