QtTaskTree::QSyncTask Class
class QtTaskTree::QSyncTask在其他任务之间同步执行自定义处理程序。更多
| 头文件: | #include <qtasktree.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS TaskTree)target_link_libraries(mytarget PRIVATE Qt6::TaskTree) |
| qmake: | QT += tasktree |
| 自 | Qt 6.11 |
| 继承: | QtTaskTree::ExecutableItem |
注意:该类中的所有函数都是可重入的。
公共函数
| QSyncTask(Handler &&handler) |
详细说明
当你想在其他任务之间执行额外的处理程序时,QSyncTask 非常有用。QSyncTask 被其父Group 视为其他任务。由于 QSyncTask 的处理程序会从调用线程同步执行,因此应避免长时间执行 QSyncTask 的处理程序。如果不可避免,可考虑使用QThreadFunctionTask 代替。
成员函数文档
[explicit] template <typename Handler, std::enable_if_t<!std::is_same_v<q20::remove_cvref_t<Handler>, QSyncTask>, bool> = true> QSyncTask::QSyncTask(Handler &&handler)
构造一个元素,同步执行传递的handler 。Handler 属于std::function<DoneResult()> 类型。由handler 返回的DoneResult 值将在父组的workflow policy 解析过程中予以考虑。也可选择接受std::function<void()> 的缩写形式。在这种情况下,假定返回值为DoneResult::Success 。
传递的handler 会在调用者线程中同步执行,因此要避免处理程序主体长时间运行。否则,请考虑使用QThreadFunctionTask 。
注意: 在报告任务树进度时,QSyncTask 元素不计入任务,也不包含在QTaskTree::taskCount() 或QTaskTree::progressMaximum() 中。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.