QtTaskTree::Iterator Class
class QtTaskTree::IteratorClasse base da utilizzare come iteratore all'interno dell'elemento For. Per saperne di più...
| Intestazione: | #include <qtasktree.h> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS TaskTree) target_link_libraries(mytarget PRIVATE Qt6::TaskTree) |
| qmake: | QT += tasktree |
| A partire da: | Qt 6.11 |
| Ereditato da: | QtTaskTree::ForeverIterator, QtTaskTree::ListIterator, QtTaskTree::RepeatIterator e QtTaskTree::UntilIterator |
| Stato: | Anteprima tecnologica |
Questa classe è in anteprima tecnologica ed è soggetta a modifiche.
Nota: tutte le funzioni di questa classe sono rientranti.
Funzioni pubbliche
Vedi anche For, ForeverIterator, RepeatIterator, UntilIterator e ListIterator.
Documentazione sulle funzioni membro
[constexpr noexcept default] Iterator::Iterator(QtTaskTree::Iterator &&other)
Crea un'istanza di ` Iterator` tramite il costrutto `move`.
qsizetype Iterator::iteration() const
Restituisce l'indice di iterazione dell'handler attualmente in esecuzione all'interno del corpo di un elemento ` Do ` del costrutto ` For (Iterator) >> `. Utilizzare questa funzione solo dall'interno del corpo dell'handler di qualsiasi elemento ` GroupItem ` inserito nel corpo dell'elemento ` Do ` della ricetta; in caso contrario, potrebbe verificarsi un crash. Assicurarsi che ` Iterator ` sia passato all'elemento ` For `.
Esempio di utilizzo:
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 << "secondi.";
};
const auto onDone = [iterator] {
qDebug() << "Finished" << iterator.iteration() << "iteration with timeout"
<< *iterator << "secondi.";
};
const Group sequentialRecipe = For(iterator) >> Do {
QTimeoutTask(onSetup, onDone)
};
const Group parallelRecipe = For(iterator) >> Do {
parallel,
QTimeoutTask(onSetup, onDone)
};L'output ottenuto eseguendo sequentialRecipe sarà:
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.In modalità sequenziale, l'ordine degli indici di iterazione negli handler `done` è garantito.
L'output ottenuto eseguendo ` parallelRecipe ` sarà:
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.In modalità parallela non è garantito che l'ordine degli indici di iterazione nei gestori `done` venga mantenuto e dipende dall'ordine delle attività completate. L'indice di iterazione restituito all'interno del gestore `done` del corpo parallelo di ` Do ` corrisponde all'indice dell'iterazione originale per il gestore `setup` corrispondente, pertanto l'ordine degli indici di iterazione nei gestori `done` successivi potrebbe non essere 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.