En esta página

QtTaskTree::RepeatIterator Class

class QtTaskTree::RepeatIterator

El iterador repetitivo que se utilizará dentro del elemento For. Más...

Cabecera: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
Desde: Qt 6.11
Hereda: QtTaskTree::Iterator

Nota: Todas las funciones de esta clase son reentrantes.

Funciones Públicas

RepeatIterator(qsizetype count)

Descripción Detallada

Véase también Iterator, ForeverIterator, UntilIterator, y ListIterator.

Documentación de las funciones miembro

[explicit] RepeatIterator::RepeatIterator(qsizetype count)

Construye el iterador repetitivo para la construcción For (RepeatIterator(count)) >> Do {}. El iterador se repetirá count veces.

Ejemplo de uso:

static const int maxTries = 5;static const int maxNumber = 10;const int luckyNumber = QRandomGenerator().global()->bounded(maxNúmero);
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(maxNúmero);    qDebug() << "You have drawn:" << drawnNumber;
   return númeroDibujado == númeroDeLaSuerte; };const auto onDone = [](DoneWith resultado) { if (resultado == DoneWith::Éxito)        qDebug() << "You have won! Congratulations!";
   else if (result == DoneWith::Error)        qDebug() << "You have lost. Try again.";
};const Group recipe { For (RepeatIterator(maxTries))>> Do { stopOnSuccess,timeoutTask(1s),        QSyncTask(onNumberCheck) },onGroupDone(onDone) };

La posible salida cuando el recipe es iniciado por el QTaskTree, y termina con éxito:

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!

En caso de que termine con un error, la salida podría ser como:

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.