QtTaskTree::RepeatIterator Class
class QtTaskTree::RepeatIteratorDer Iterator für die Wiederholung, der innerhalb des „For“-Elements verwendet werden soll. Mehr...
| Header: | #include <qtasktree.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS TaskTree) target_link_libraries(mytarget PRIVATE Qt6::TaskTree) |
| qmake: | QT += tasktree |
| Seit: | Qt 6.11 |
| Erbt von: | QtTaskTree::Iterator |
| Status: | Technologievorschau |
Diese Klasse befindet sich in der Technologievorschau und kann sich noch ändern.
Hinweis: Alle Funktionen in dieser Klasse sind reentrant.
Öffentliche Funktionen
| RepeatIterator(qsizetype count) |
Siehe auch „ Iterator“ , „ ForeverIterator “, „ UntilIterator “ und „ ListIterator “.
Dokumentation zu den Mitgliedsfunktionen
[explicit] RepeatIterator::RepeatIterator(qsizetype count)
Erstellt den Wiederholungsiterator für die Konstruktion „For (RepeatIterator(count)) >> Do {}“. Der Iterator wird count -mal wiederholt.
Anwendungsbeispiel:
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 (Ergebnis== DoneWith::Fehler)
qDebug() << "You have lost. Try again.";
};
const Group recipe {
For (RepeatIterator(maxTries)) >> Do {
stopOnSuccess,
timeoutTask(1s),
QSyncTask(onNumberCheck)
},
onGroupDone(onDone)
};Die mögliche Ausgabe, wenn „ recipe “ von „ QTaskTree “ gestartet wird und erfolgreich abgeschlossen wird:
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!Falls die Ausführung mit einem Fehler endet, könnte die Ausgabe wie folgt aussehen:
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.