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 |
注意:该类中的所有函数都是可重入的。
公共函数
| qsizetype | iteration() const |
另请参见 For,ForeverIterator,RepeatIterator,UntilIterator, 和ListIterator 。
成员函数文档
qsizetype Iterator::iteration() const
返回Do For (Iterator) >> 结构体内部当前执行处理程序的迭代索引。Do 该函数只能在GroupItem 元素的处理程序体中使用,否则可能会导致崩溃。请确保Iterator 已传递给For 元素。
使用示例:
常量QList<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" << *iterator <<"秒。"; };constGroup sequentialRecipe=For(iterator)>>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.
在顺序模式中,已完成处理程序中迭代索引的顺序保证得到保留。
执行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.
在并行模式下,已完成处理程序中的迭代索引顺序不保证不变,而是取决于已完成任务的顺序。并行Do 主体的已完成处理程序中返回的迭代索引与相应设置处理程序的原始迭代索引相匹配,因此后续已完成处理程序中的迭代索引顺序可能不是升序。
© 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.