이 페이지에서

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 int maxTries = 5;static const int maxNumber = 10;const int luckyNumber = QRandomGenerator().global()->bounded(maxNumber);
qDebug() << "Today's lucky number is:" << luckyNumber;
qDebug() << "You have" << maxTries << "lottery tickets.";
qDebug() << "Let's start the drawing...";

const auto onNumberCheck = [luckyNumber] { const int drawnNumber = QRandomGenerator().global()->bounded(maxNumber);    qDebug() << "You have drawn:" << drawnNumber;
   return drawnNumber== luckyNumber; };const auto onDone = [](DoneWith result) { if (result== DoneWith::Success)        qDebug() << "You have won! Congratulations!";
   else if (결과== DoneWith::Error)        qDebug() << "You have lost. Try again.";
};const Group recipe { For (RepeatIterator(maxTries))>> Do { stopOnSuccess,timeoutTask(1s),        QSyncTask(onNumberCheck) },onGroupDone(onDone) };

recipeQTaskTree 에 의해 시작되어 성공으로 완료되었을 때 가능한 출력입니다:

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.