paolom
17th July 2012, 11:45
Hi,
I've a plugin and in this plugin I need to have a worker thread whit an event loop that get some work to do.
QThread * th = new QThread(this);
m_workerJob = new WorkerJob;
connect(m_workerJob,SIGNAL(stopThread()),th,SLOT(q uit()));
connect(this,SIGNAL(stopThread()),m_workerJob,SIGN AL(stopThread()));
connect(this,SIGNAL(doWork()),m_workerJob,SLOT(doW ork()));
m_workerJob->moveToThread(th);
th->start();
Then, when I close my application, I want to be sure that my workerJob is finished.
I've this code that I call before to close the application:
QThread * th = m_workerJob->thread();
emit stopThread();
th->wait();
This function is blocking. The problem is that the SIGNAL stopThread() is not processed cause it need to return to the event loop to be processed, while the wait() is a blocking function.
I want to wait synchronously the exit of the worker thread. So, how can I solve it??
Thanks
I've a plugin and in this plugin I need to have a worker thread whit an event loop that get some work to do.
QThread * th = new QThread(this);
m_workerJob = new WorkerJob;
connect(m_workerJob,SIGNAL(stopThread()),th,SLOT(q uit()));
connect(this,SIGNAL(stopThread()),m_workerJob,SIGN AL(stopThread()));
connect(this,SIGNAL(doWork()),m_workerJob,SLOT(doW ork()));
m_workerJob->moveToThread(th);
th->start();
Then, when I close my application, I want to be sure that my workerJob is finished.
I've this code that I call before to close the application:
QThread * th = m_workerJob->thread();
emit stopThread();
th->wait();
This function is blocking. The problem is that the SIGNAL stopThread() is not processed cause it need to return to the event loop to be processed, while the wait() is a blocking function.
I want to wait synchronously the exit of the worker thread. So, how can I solve it??
Thanks