QRunnable尝试中止任务

编程入门 行业动态 更新时间:2024-10-11 11:19:33
本文介绍了QRunnable尝试中止任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以中止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尝试中止任务

本文发布于:2023-11-13 04:28:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:QRunnable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!