QtTaskTree::Iterator Class
class QtTaskTree::Iterator用作 For 元素内部迭代器的基类。更多内容...
| 头文件: | #include <qtasktree.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS TaskTree) target_link_libraries(mytarget PRIVATE Qt6::TaskTree) |
| qmake: | QT += tasktree |
| 自: | Qt 6.11 |
| 由以下版本继承: | QtTaskTree::ForeverIterator、QtTaskTree::ListIterator 、QtTaskTree::RepeatIterator 以及QtTaskTree::UntilIterator |
| 状态: | 技术预览 |
该类处于技术预览阶段,内容可能会有变动。
注意:此类中的所有函数均为可重入函数。
公共函数
另请参阅 For 、ForeverIterator 、RepeatIterator 、UntilIterator 和ListIterator 。
成员函数文档
[constexpr noexcept default] Iterator::Iterator(QtTaskTree::Iterator &&other)
通过Move构造一个Iterator 的实例。
qsizetype Iterator::iteration() const
返回在以下结构中Do 主体内当前正在执行的处理程序的迭代索引:For (Iterator) >> 。请仅在位于食谱Do 主体内的任何GroupItem 元素的处理程序主体中调用此函数,否则可能会导致程序崩溃。请确保已将Iterator 传递给For 元素。
使用示例:
constQList<std::chrono::seconds>timeouts={5s, 1s, 3s};
constListIterator iterator(timeouts);
const autoonSetup= [iterator](std::chrono::milliseconds &timeout) {
timeout= *iterator;
qDebug() << "Starting" << iterator.iteration() << "iteration with timeout"
<< *iterator << "秒。";
};
const autoonDone= [iterator]{
qDebug() << "Finished" << iterator.iteration() << "iteration with timeout"
<< *迭代器 << "秒。";
};
constGroup sequentialRecipe=For(迭代器)>>Do {
QTimeoutTask(onSetup,onDone)
};
constGroup parallelRecipe=For(iterator)>>Do {
parallel,
QTimeoutTask(onSetup,onDone)
};执行sequentialRecipe 时的输出结果为:
Starting 0 iteration with timeout 5s seconds.
Finished 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Finished 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 2 iteration with timeout 3s seconds.在顺序模式下,done 处理程序中迭代索引的顺序将得到保证。
执行parallelRecipe 时的输出结果为:
Starting 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 1 iteration with timeout 1s seconds.
Finished 2 iteration with timeout 3s seconds.
Finished 0 iteration with timeout 5s seconds.在并行模式下,done处理程序中迭代索引的顺序无法保证保持不变,且取决于任务完成的顺序。并行Do 主体中done处理程序返回的迭代索引与原始迭代中对应setup处理程序的索引相匹配,因此后续done处理程序中迭代索引的顺序可能并非递增。
© 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.