是否可以中止QRunnable任务?
Is it possible to abort a QRunnable task?
即使在文档中,我也找不到任何方法.
I can't find any way to do it even in the documentation.
非常感谢
推荐答案不,您不能中止QRunnable任务.
No, you cannot abort a QRunnable task.
在Qt中弄脏线程的唯一方法是通过QThread::terminate()(不鼓励使用).
The only way to dirty-abort a thread in Qt is through QThread::terminate() (which is discouraged).
QThreadPool在后台使用QThread运行QRunnable任务,但是它没有为开发人员提供调用QThread::terminate()的方法.因此,QRunnable无法中止.
QThreadPool uses QThread behind-the-scenes to run QRunnable tasks, but it doesn't provide a way for developers to call QThread::terminate(). Therefore, QRunnable cannot be aborted.
我建议您重新设计应用程序-请参阅Qa中的多线程技术概述使用线程的所有方式,并选择与您的用例匹配的解决方案.
I recommend redesigning your application -- refer to Multithreading Technologies in Qt to get an overview of all the ways you can use threads, and select a solution that matches your use case.
更多推荐
QRunnable尝试中止任务
发布评论