[Interest] How to start object in the thread?

K. Frank kfrank29.c at gmail.com
Sun Jun 8 16:05:35 CEST 2014


Hello Igor!

On Sun, Jun 8, 2014 at 6:42 AM,  <igor.mironchik at gmail.com> wrote:
> I’ve added Launcher that works on the main thread. His job is just emit
> start() signal.
> My Object on the different thread connects to this start() signal.
>
> Now Launcher emits start() signal. All is ok. But Object doesn’t receive
> it... Why?
>
> From: igor
> Sent: Sunday, June 08, 2014 12:10 PM
> ...
> Hi,
>
> for example I have Object with slot start.
> And I create that object with the next code:
> QCoreApplication app( argc, argv );
> Object o;
> QThread t;
> o.moveToThread( &t );
> t.start();
> QTimer::singleShot( 0, &o, SLOT( start() ) );
> app.exec();
>
> But this code doesn’t invoke slot start() after launching.

Your code looks right to me.  (I'm not saying it is right -- I haven't
tried it and it's easy for me to overlook errors that ought to be
obvious.)

> And there is my question: how to invoke SLOT start() of Object on the
> different thread and app start-up?

Could you show the code for Object?  Or if Object actually
does something, could you show the code for a stripped-down
version that demonstrates the same issue?

Some trivial questions, but just to be sure:  Does Object derive
from QObject?  If so, how?  How do you know that Object::start()
isn't being called?  How is your code instrumented?

> Thanks.


Good luck!


K. Frank



More information about the Interest mailing list