Auf dieser Seite

QtTaskTree::ForeverIterator Class

class QtTaskTree::ForeverIterator

Unendlicher Iterator zur Verwendung innerhalb eines „For“-Elements. 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

Ausführliche Beschreibung

Siehe auch „ Iterator“ , „ RepeatIterator “, „ UntilIterator “ und „ ListIterator “.

Dokumentation zu den Mitgliedsfunktionen

ForeverIterator::ForeverIterator()

Erstellt einen endlosen Iterator für die Konstruktion „For (ForeverIterator()) >> Do {}“.

Hinweis: Seien Sie besonders vorsichtig, wenn Ihr „Do“-Körper den Parallelmodus angibt – in diesem Fall kann der „ QTaskTree “ eine unendliche Anzahl von Tasks instanziieren.

Anwendungsbeispiel:

static const int maxNumber = 10;
const int luckyNumber = QRandomGenerator().global()->bounded(maxNumber);

qDebug() << "Today's lucky number is:" << luckyNumber;
qDebug() << "Let's start the drawing...";

const auto onNumberCheck = [luckyNumber] {
    const int drawnNumber = QRandomGenerator().global()->bounded(maxNumber);
    qDebug() << "You have drawn:" << drawnNumber;
   bool gewonnen = gezogeneZahl== Glückszahl;
    if (gewonnen)
        qDebug() << "You have won! Congratulations!";
   return won;
};

const Group recipe = For (ForeverIterator()) >> Do {
    stopOnSuccess,
    timeoutTask(1s),
    QSyncTask(onNumberCheck)
};

Die mögliche Ausgabe, wenn der ` recipe ` vom ` QTaskTree` gestartet wird:

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.