PDA

View Full Version : QThread



merlvingian
26th December 2006, 17:28
Is there any simple way to wakeup a thread from QThread::msleep().

Using QTimer as a single shot and putting the thread in a while loop looking for a close and cleanup call seems like more system overhead while QTimer::start() only has an integer resolution and QThread::msleep() has unsigned long being another caveat. I could piggyback QTimers but it would just be more kludged code.

I noticed I can call QThread::terminate but from the docs it does not appear to let me clean up the thread in any way.

Any suggestions on the best way to implement a thread that has a sleep condition and still be able to interrupt and cleanup the thread at any point?

wysota
26th December 2006, 17:31
Is there any simple way to wakeup a thread from QThread::msleep().
There is no way of waking a thread from a sleep.


Using QTimer as a single shot and putting the thread in a while loop looking for a close and cleanup call seems like more system overhead while QTimer::start() only has an integer resolution and QThread::msleep() has unsigned long being another caveat. I could piggyback QTimers but it would just be more kludged code.
Maybe you could use a QWaitCondition instead?

charlesD
27th December 2006, 18:41
I'm not sure what you are trying to do, but you could call QApplication:: processEvents() in a loop and just check a flag that you can set or clear from another thread to break out of the loop when you are ready.