Threadweaver::JobRunHelper::runTheJob failed/done Signals

Andreas Pakulat apaku at gmx.de
Wed Sep 10 08:00:48 BST 2008


On 08.09.08 19:34:24, Alejandro Wainzinger wrote:
> In the Threadweaver::JobRunHelper::runTheJob method(
> KDE/kdelibs/threadweaver/Weaver/Job.cpp ), there is the following
> piece of code:
> 
> if ( ! job->success() )
>     {
>         emit ( failed( job ) );
>     }
> 
>     emit ( done( job ) );
> 
> I've subclassed a Threadweaver::Job, and reimplemented the success()
> method, and connected the appropriate signals/slots for done/failed
> signals that are emitted as shown above.  With this code though, both
> the failed and done signals are emitted, and so both slots are called,
> which is not what I want.  I only want the failed slot to be called if
> it fails.  I'm wondering why the above piece of code isn't an if-else.

Because its correct. Wether a job has failed or not doesn't have any
influence of the job being done. That is, the job has reached the end of
its execution, with some kind of result. Its a design decision the
ThreadWeaver author made.

> I think I can accomplish what I want by having the slot triggered by
> the failed signal, disconnect the connection to the slot triggered by
> the done signal.  Is that the right way of doing this?  It seems a bit
> ugly, as the only way I can do that is by using the QObject sender()
> method.

No, definetly not. You simply need to make sure that whatever your
"done-slot" does is only executed when job->success() == true.

Andreas

-- 
You will overcome the attacks of jealous associates.




More information about the kde-core-devel mailing list