PDA

View Full Version : Waiting on a thread?



MrGarbage
3rd November 2007, 14:09
I have a windows QT app where there are essentially 2 threads.

There is a worker thread that was created via CreateThread().
This is processing some asynchronously received data.

There is the GUI thread itself which upon some user action
initiates a write of some data and then after some time gets called
back with some rx data by the Thread.

Therefore I need a way to loop/wait until the callback occurs or
timeout, but not block the Thread processing while I wait.

I tried a QWaitCondition and a QMutex, but that seems to block the
Thread while I'm waiting...

Seems like I should be able to do this with some combination of the
QT semaphore/events handlers and without using an actual timer.

Any suggestions?

Thanks

Mark

DeepDiver
3rd November 2007, 16:13
To "send" data from the worker thread to the gui-thread you can use Qt's signal and slot mechanism and emit a signal from the wroker thread after you got the data.

For the timeout mechanism you can use a timer ...

Just my two cents ....

Good luck,

Tom