このページでは

QtTaskTree::RepeatIterator Class

class QtTaskTree::RepeatIterator

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::Iterator
ステータス: テクノロジープレビュー

このクラスはテクノロジープレビュー段階にあり、変更される可能性があります。

注:このクラスのすべての関数は再入可能である。

パブリック関数

RepeatIterator(qsizetype count)

詳細な説明

関連項目: Iterator 、ForeverIterator 、UntilIterator 、およびListIterator 。

メンバー関数のドキュメント

[explicit] RepeatIterator::RepeatIterator(qsizetype count)

For (RepeatIterator(count)) >> Do {} という構文用の反復イテレータを生成します。このイテレータは、count 回反復されます。

使用例:

static const intmaxTries= 5;
static const intmaxNumber= 10;
const intluckyNumber=QRandomGenerator().global()->bounded(maxNumber);

qDebug() << "Today's lucky number is:" << luckyNumber;
qDebug() << "You have" << maxTries << "lottery tickets.";
qDebug() << "Let's start the drawing...";

const autoonNumberCheck= [luckyNumber]{
    const intdrawnNumber=QRandomGenerator().global()->bounded(maxNumber);
    qDebug() << "You have drawn:" << drawnNumber;
   returndrawnNumber==luckyNumber;
};

const autoonDone= [](DoneWith result) {
    if(result==DoneWith::Success)
        qDebug() << "You have won! Congratulations!";
   else if(result==DoneWith::Error)
        qDebug() << "You have lost. Try again.";
};

constGroup recipe {
    For (RepeatIterator(maxTries))>>Do {
        stopOnSuccess,
        timeoutTask(1s),
        QSyncTask(onNumberCheck)
    },
    onGroupDone(onDone)
};

QTaskTree によってrecipe が開始され、正常に終了した場合の可能な出力:

Today's lucky number is: 6
You have 5 lottery tickets.
Let's start the drawing...
You have drawn: 9
You have drawn: 6
You have won! Congratulations!

エラーで終了した場合、出力は次のようなものになる可能性があります:

Today's lucky number is: 8
You have 5 lottery tickets.
Let's start the drawing...
You have drawn: 1
You have drawn: 7
You have drawn: 6
You have drawn: 7
You have drawn: 2
You have lost. Try again.

© 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.