
Originally Posted by
themusicalguy
I've had a look over the QWaitCondition documentation and I must confess I'm still not sure how to use it, at least not how to apply it to my situation. Could you give a small example if it isn't too much trouble?
// thread's part:
forever {
mutex.lock();
while( queue.empty() ) {
queueNotEmptyCondition.wait( & mutex );
}
Task * task = getTaskFromQueue();
mutex.unlock();
task->process();
delete task;
};
// task scheduling:
mutex.lock();
queue.append( task );
mutex.unlock();
queueNotEmptyCondition.wakeOne();
// thread's part:
forever {
mutex.lock();
while( queue.empty() ) {
queueNotEmptyCondition.wait( & mutex );
}
Task * task = getTaskFromQueue();
mutex.unlock();
task->process();
delete task;
};
// task scheduling:
mutex.lock();
queue.append( task );
mutex.unlock();
queueNotEmptyCondition.wakeOne();
To copy to clipboard, switch view to plain text mode
Of course if you use queued connections, Qt does most of this for you.

Originally Posted by
themusicalguy
as I understand it Runner would still exist in the main thread, only the Runner::run() method would be in the new thread therefore any signal / slot connections would be processed in the main thread anyway.
Yes, it's a bit problematic in Qt, but you can use moveToThread() as Marcel has suggested or you can split implementation into Runner object and a RunnerThread that hosts it.
Bookmarks