在本页

QtTaskTree::ForeverIterator Class

class QtTaskTree::ForeverIterator

用于 For 元素内部的无限迭代器。更多

Header: #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

注意:该类中的所有函数都是可重入的

公共函数

详细说明

另请参见 Iterator,RepeatIterator,UntilIterator, 和ListIterator

成员函数文档

ForeverIterator::ForeverIterator()

为 For (ForeverIterator()) >> Do {} 构造构建永不终止的迭代器。

注意: 如果 Do 主体指定了并行模式,请务必小心--在这种情况下,QTaskTree 可能会实例化无限多的任务。

使用示例

static const intmaxNumber= 10;const intluckyNumber=QRandomGenerator().global()->bounded(maxNumber);
qDebug() << "Today's lucky number is:" << luckyNumber;
qDebug() << "Let's start the drawing...";

const autoonNumberCheck= [luckyNumber]{const intdrawnNumber=QRandomGenerator().global()->bounded(maxNumber);    qDebug() << "You have drawn:" << drawnNumber;
   boolwon=drawnNumber==luckyNumber;if(won)        qDebug() << "You have won! Congratulations!";
   returnwon; };constGroup recipe=For (ForeverIterator())>>Do { stopOnSuccess,timeoutTask(1s)QSyncTask(onNumberCheck) };

QTaskTree 启动recipe 时的可能输出:

Today's lucky number is: 8
Let's start the drawing...
You have drawn: 2
You have drawn: 2
You have drawn: 6
You have drawn: 7
You have drawn: 9
You have drawn: 8
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.