Set QThread wait for unlimited amount of time
-
How can I 'freeze' a thread for unlimited amount of time?
I see both wait conditions and sleep methods accept some time amount to keep sleeping.Is the only way to set a large number for the wait time? -
I would say that if you have a situation where you need to pause a thread for unknown (large) amount of time, it is better to completely stop it (exit from the event loop, using exit() function). Then start it up again, when it is needed.
-
In most cases you would be right.But I have OpenGL rendering thread with tons of stuff happening in a 'run()' method.I need to freeze the rendering until the user decides to go to the next frame.Theoretically it may never happen(the user remains on the same frame till the app exit() ) So I don't think restarting the thread for each next rendered frame is a good idea.
-
Do you have a loop in your run()? Then you could introduce a boolean variable, say isFrozen and set it when your thread needs to freeze. After that, you can check in your loop, whether the thread is allowed to go forward; if not - call sleep(). Not an elegant solution, perhaps, but it may work.
-
Why yes, there is QWaitCondition. See "the docs":http://qt-project.org/doc/qt-5/QWaitCondition.html.