En esta página

QtTaskTree::Iterator Class

class QtTaskTree::Iterator

Clase base para ser utilizada como iterador 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
Heredado por:

QtTaskTree::ForeverIterator, QtTaskTree::ListIterator, QtTaskTree::RepeatIterator, y QtTaskTree::UntilIterator

Nota: Todas las funciones de esta clase son reentrantes.

Funciones Públicas

qsizetype iteration() const

Descripción detallada

Véase también For, ForeverIterator, RepeatIterator, UntilIterator, y ListIterator.

Documentación de las funciones miembro

qsizetype Iterator::iteration() const

Devuelve el índice de iteración del manejador actualmente en ejecución dentro de un cuerpo Do de la construcción For (Iterator) >> . Utilice esta función sólo desde dentro del cuerpo del manejador de cualquier elemento GroupItem colocado en el cuerpo Do de la receta, de lo contrario puede esperar un fallo. Asegúrese de que Iterator se pasa al elemento For.

Ejemplo de uso:

const QList<std::chrono::seconds> timeouts = { 5s, 1s, 3s };const ListIterator iterator(timeouts);const auto onSetup = [iterator](std::chrono::milliseconds &timeout) { timeout = *iterator;    qDebug() << "Starting" << iterator.iteration() << "iteration with timeout"
            << *iterator<< "segundos."; };const auto onDone = [iterator] {    qDebug() << "Finished" << iterator.iteration() << "iteration with timeout"
            << *iterator<< "segundos."; };const Group sequentialRecipe = For(iterator)>> Do { QTimeoutTask(onSetup, onDone) };const Group parallelRecipe = For(iterator)>> Do { parallel,    QTimeoutTask(onSetup, onDone) };

La salida al ejecutar sequentialRecipe será:

Starting 0 iteration with timeout 5s seconds.
Finished 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Finished 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 2 iteration with timeout 3s seconds.

En modo secuencial se garantiza la conservación del orden de los índices de iteración en los manejadores done.

La salida al ejecutar parallelRecipe será:

Starting 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 1 iteration with timeout 1s seconds.
Finished 2 iteration with timeout 3s seconds.
Finished 0 iteration with timeout 5s seconds.

En modo paralelo el orden de los índices de iteración en los manejadores done no está garantizado, y depende del orden de las tareas terminadas. El índice de iteración devuelto dentro del manejador hecho del cuerpo paralelo de Do coincide con el índice de la iteración original para el manejador de configuración correspondiente, por lo que el orden de los índices de iteración en los manejadores hechos subsiguientes puede no ser ascendente.

© 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.