- Extending Qt Creator Manual
- QtTaskTree
- Do
- Extending Qt Creator Manual 20.0.0-rc1

# QtTaskTree::Do Class

class QtTaskTree::Do

A body element used with For and When constructs. More...

Header: | `#include <qtasktree.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS TaskTree)` `target_link_libraries(mytarget PRIVATE Qt6::TaskTree)`
qmake: | `QT += tasktree`
Since: | 6.11

- List of all members, including inherited members

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.

See also For and When.

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