QRunnable trying to abort a task

前端 未结 2 1605
广开言路
广开言路 2020-12-07 03:49

Is it possible to abort a QRunnable task?

I can\'t find any way to do it even in the documentation.

Thanks a lot

2条回答
  •  Happy的楠姐
    2020-12-07 04:32

    Qt shares a thread object model similar to many other frameworks (the .NET languages and Java come to mind). In these type of frameworks, it is generally discouraged to try to "abort" a thread. Other threading implementations (like POSIX) are largely the same way. It's bad practice to dirty-kill a thread.

    Instead, construct your logic inside run() in such a way that you can put "checkpoints" in every so often to determine if the run() function can safely terminate. These checkpoints should check a flag (or some other sentinel) that indicates that the thread should end.

提交回复
热议问题