views:

48

answers:

3

Hi,

i want my application to wait indefinitely till a task gets completed in another thread. How to perform this in Qt.

in windows we use waitforsingletonobject but is there any alternative to this. can i get some hints from you guys..

Thanks

+2  A: 

Waiting for threads to finish certain tasks (thread synchronization) is the job of the QWaitCondition class.

gspr
A: 

Call wait on your QThread object.

Idan K
Since he was referring to "a task" getting completed, I don't think he wants to wait for the entire thread to finish.
gspr
if they use `WaitForSingleObject` on Windows, the Qt equivalent would be doing this.
Idan K
wait keeps UI hung i guess, but till what extent i have to wait, infinite amount of time i have to..in this case how to do
Shadow
without more information it's hard to give any worthy advice. if there's a UI involved, you probably need to use signals/slots. edit your question to provide more details.
Idan K
A: 

Use QtConcurrent::run. See my answer to this question. Note that the QFutureWatcher API can work in blocking (the waitForFinished method) and non-blocking (the finished signal) modes.

andref