QtTaskTree::Do Class
class QtTaskTree::DoA body element used with For and When constructs. More...
Header: | #include <qtasktree.h> |
Note: All functions in this class are reentrant.
Public Functions
Do(const QtTaskTree::GroupItems &children) | |
Do(std::initializer_list<QtTaskTree::GroupItem> children) |
Detailed Description
A body element, holding a list of tasks to be executed on each For iteration or after When's barrier was advanced.
For (RepeatIterator(5)) >> Do { task1, task2 };
In case of For loop, the Do's body will be executed multiple times. If onGroupSetup() or onGroupDone() handlers are a part of passed children to Do's constructor, they will be executed just once - before the whole loop starts, and after the whole loop is finished:
const RepeatIterator iterator(3); const auto onSetup = [] { qDebug() << "Setup"; }; const auto onSync = [iterator] { qDebug() << "Current iteration:" << iterator->iteration(); }; const auto onDone = [] { qDebug() << "Done"; }; const Group recipe = For (iterator) >> Do { onGroupSetup(onSetup), QSyncTask(onSync), onDone(onDone) };
The above recipe, when executed, will output:
Setup Current iteration: 0 Current iteration: 1 Current iteration: 2 Done
If the intention is to invoke group handlers on each iteration, enclose the Do body with an extra Group, like:
const Group recipe = For (iterator) >> Do { Group { onGroupSetup(onSetup), QSyncTask(onSync), onDone(onDone) } };
The latter recipe, when executed, will output:
Setup Current iteration: 0 Done Setup Current iteration: 1 Done Setup Current iteration: 2 Done
The similar happens when the Storage passed as a direct child of the body. The storage structure is instantiated just once, before the whole loop starts, and is destroyed just after the whole loop is finished. If the intention is to have separate instance of the Storage for each iteration, enclose the Do body with an extra Group.
Be careful with placing parallel element in the Do's body of the For loop, as all iterations will start in parallel. This might not be desired, especially in case of ForeverIterator.
Member Function Documentation
[explicit]
Do::Do(const QtTaskTree::GroupItems &children)
Constructs a Do body with children to be executed on each For's iteration or after When's barrier was advanced.
[explicit]
Do::Do(std::initializer_list<QtTaskTree::GroupItem> children)
Constructs a Do body with children passed as initializer list.
This is an overloaded function.
© 2025 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.