Threadweaver or QThread?

Andreas Pakulat apaku at gmx.de
Thu Sep 27 16:10:21 BST 2007


On 27.09.07 16:34:18, Mirko Boehm wrote:
> Andreas Pakulat wrote:
> ...
> 
> >> * 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)
> Now this reply worries me - using events is rather old-fashioned and
> rough.

Well, thats news to me :)

> If you want to transport data - send a pointer to the job object,
> and add methods to retrieve the job objects properties (remember, the
> driving thread is in a wait condition, so you already took care of
> synchronization). And the pointer can easily be a slot argument. No need
> for a event class, et cetera.

Well, I'm not 100% sure what to do. Currently I've only seen simple data
(a QString, QString+ some int and a custom complex structure), so yes
signals would work there. But I don't want to store the data in the job
as it won't need the data outside of the callback that is going to send
the even/signal (and wait for the result).

> >> 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.
> It is not the same thing - a Job is a QObject, but not a QThread.

I know, but I can treat it like a QThread in one or two places (for
example using a QWaitCondition in the run method). Thats what I meant.

Andreas 

-- 
You will be the victim of a bizarre joke.




More information about the kde-core-devel mailing list