connect( th, SIGNAL( started() ), thObj, SLOT(doJob()), Qt::QueuedConnection ); //start thObj
connect( thObj, SIGNAL( finThObj( int ) ), this, SLOT(thJobFin(int)), Qt::DirectConnection ); //job done Direct ret
connect( thObj, SIGNAL( thObjQuit() ), th, SLOT(quit()), Qt::QueuedConnection ); // queued quit
connect( th, SIGNAL( finished() ), this, SLOT(thQuit()), Qt::QueuedConnection ); //clean up i.e. delete th and thObj
connect( th, SIGNAL( started() ), thObj, SLOT(doJob()), Qt::QueuedConnection ); //start thObj
connect( thObj, SIGNAL( finThObj( int ) ), this, SLOT(thJobFin(int)), Qt::DirectConnection ); //job done Direct ret
connect( thObj, SIGNAL( thObjQuit() ), th, SLOT(quit()), Qt::QueuedConnection ); // queued quit
connect( th, SIGNAL( finished() ), this, SLOT(thQuit()), Qt::QueuedConnection ); //clean up i.e. delete th and thObj
To copy to clipboard, switch view to plain text mode
Everything, except finThObj(int), is queued. finThObj(), in my opinion (please correct me if I'm wrong), should return immediately after execution.
void objThDirConn::doJob()
{
qDebug() << "thread job: in " << this->thread();
int k = 0;
for( int i = 0; i < 1000000000; ++i)
{
k++;
}
emit finThObj( k );
emit thObjQuit();
}
void objThDirConn::doJob()
{
qDebug() << "thread job: in " << this->thread();
int k = 0;
for( int i = 0; i < 1000000000; ++i)
{
k++;
}
emit finThObj( k );
emit thObjQuit();
}
To copy to clipboard, switch view to plain text mode
Bookmarks