Nesta página

QtTaskTree::ForeverIterator Class

class QtTaskTree::ForeverIterator

Iterador infinito para ser usado dentro do elemento `For`. Mais...

Cabeçalho: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
Desde: Qt 6.11
Herdado de: QtTaskTree::Iterator
Status: Pré-visualização tecnológica

Esta classe está em pré-visualização tecnológica e está sujeita a alterações.

Observação: Todas as funções desta classe são reentrantes.

Funções públicas

Descrição detalhada

Veja também Iterator, RepeatIterator, UntilIterator e ListIterator.

Documentação das funções de membro

ForeverIterator::ForeverIterator()

Cria um iterador infinito para a construção For (ForeverIterator()) >> Do {}.

Observação: tenha muito cuidado se o corpo da instrução `Do` especificar o modo paralelo — nesse caso, o ` QTaskTree ` poderá instanciar um número infinito de tarefas.

Exemplo de uso:

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 ganhou = numeroSorteado== numeroDaSorte;
    if (ganhou)
        qDebug() << "You have won! Congratulations!";
   return won;
};

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

A saída possível quando o ` recipe ` é iniciado pelo ` QTaskTree`:

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.