What is the QThread::wait() function for?
-
Regarding QThread::wait(), the official documentation has a sentence that says it provides functionality similar to the POSIX pthread_join() function.
This statement makes me wonder if wait() has a function to reclaim thread resources?
Do I need to use wait() after a thread has finished executing? If it really does reclaim the thread's resources, then I guess I'd still need to call wait().
Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.
So when should I call wait() manually?
-
@mq-loser said in What is the QThread::wait() function for?:
This statement makes me wonder if wait() has a function to reclaim thread resources?
Do I need to use wait() after a thread has finished executing?
Why should you have to wait for a finished thread? wait() waits for the thread to finish in the same way pthread_join() is waiting.
-
@mq-loser said in What is the QThread::wait() function for?:
This statement makes me wonder if wait() has a function to reclaim thread resources?
What does this mean exactly? A thread is a function (i.e. a root of a call stack), so what resources you expect
wait()
to "reclaim"?Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.
So when should I call wait() manually?You have to call
wait()
before theQThread
destructor is run, so you can be sure that the thread has exited before internal cleanup can be done. If you want to get a notification for when the thread has exited, then you can get that by connecting to theQThread::finished
signal - you may do that for example to clean up some (worker) object that you'd moved to the thread. -