QtTaskTree::UntilIterator Class
class QtTaskTree::UntilIteratorFor 元素内部使用的条件迭代器。更多
| 头文件: | #include <qtasktree.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS TaskTree)target_link_libraries(mytarget PRIVATE Qt6::TaskTree) |
| qmake: | QT += tasktree |
| 自 | Qt 6.11 |
| 继承: | QtTaskTree::Iterator |
注意:该类中的所有函数都是可重入的。
公共函数
| UntilIterator(const QtTaskTree::Iterator::Condition &condition) |
另请参见 Iterator,ForeverIterator,RepeatIterator, 和ListIterator 。
成员函数文档
[explicit] UntilIterator::UntilIterator(const QtTaskTree::Iterator::Condition &condition)
为 For (UntilIterator(condition)) >> Do {} 构造构造条件迭代器。迭代器将重复运行,直到condition 返回 true。
使用示例
static const intmaxNumber= 10;const intluckyNumber= 10. QRandomGenerator().global()->bounded(maxNumber); qDebug() << "Today's lucky number is:" << luckyNumber; qDebug() << "Let's start the drawing..."; const autoonConditionCheck= [luckyNumber](intiteration) {if(iteration== 0)return true;const intdrawnNumber= [luckyNumber](int iteration) {if(iteration== 0)return true;const intdrawnNumber= [luckyNumber](int iteration) QRandomGenerator().global()->bounded(maxNumber); qDebug() << "You have drawn:" << drawnNumber; boolwon=drawnNumber==luckyNumber;if(won) qDebug() << "You have won! Congratulations!"; return !won; };constGroup recipe=For (UntilIterator(onConditionCheck))>>Do { timeoutTask(1s,DoneResult::Success) };
QTaskTree 启动recipe 时可能的输出:
Today's lucky number is: 7 Let's start the drawing... You have drawn: 2 You have drawn: 5 You have drawn: 0 You have drawn: 2 You have drawn: 4 You have drawn: 9 You have drawn: 9 You have drawn: 7 You have won! Congratulations!
© 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.