Custom function interrupt

前端 未结 2 982
不思量自难忘°
不思量自难忘° 2021-01-29 00:58

Is it possible to implement function interrupt in Qt (5.x).

For example if I have a button and want something to execute on the thread (which is running infinite loop) w

2条回答
  •  半阙折子戏
    2021-01-29 01:29

    You could start a thread and then immediately wait on a std::condition_variable, then when the button is clicked (the event being called on the main thread), notify the condition variable and the thread would awake.

    However, this is a bit strange. What are you trying to do? call an asynchronous task upon a button click? In that case, perhaps it would be better just to start one from the button click event with std::packaged_task or std::async.

提交回复
热议问题