- Qt 6.12
- Qt TaskTree
- C++ Classes
- Group
- Qt 6.12.0 Reference Documentation

# QtTaskTree::Group Class

class QtTaskTree::Group

Group represents the basic element for composing declarative recipes describing how to execute and handle a nested tree of asynchronous tasks. More...

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

This class is in technology preview and is subject to change.

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| Group(const QtTaskTree::GroupItems &children)
| Group(std::initializer_list<QtTaskTree::GroupItem> children)

## Detailed Description

Group is a container for other group items. It encloses child tasks into one unit, which is seen by the group's parent as a single, asynchronous task. Since Group is of the GroupItem type, it may also be a child of Group.

Insert child tasks into the group by using aliased custom task names, such as, QThreadFunctionTask<`ResultType`> or QNetworkReplyWrapperTask:

     const Group group {
         QNetworkReplyWrapperTask(...),
         QThreadFunctionTask<int>(...)
     };

You can customize the group's behavior by inserting the ExecutionMode or WorkflowPolicy items:

     const Group group {
         parallel,
         continueOnError,
         QNetworkReplyWrapperTask(...),
         QNetworkReplyWrapperTask(...)
     };

The group may contain nested groups:

     const Group group {
         finishAllAndSuccess,
         QNetworkReplyWrapperTask(...),
         Group {
             QNetworkReplyWrapperTask(...),
             Group {
                 parallel,
                 QNetworkReplyWrapperTask(...),
                 QNetworkReplyWrapperTask(...),
             }
             QThreadFunctionTask<QString>(...)
         }
     };

The group may dynamically instantiate a custom storage structure, which may be used for inter-task data exchange:

     struct MyCustomStruct { QByteArray data; };

     Storage<MyCustomStruct> storage;

     const auto onFirstSetup = [](QNetworkReplyWrapper &task) { ... };
     const auto onFirstDone = [storage](const QNetworkReplyWrapper &task) {
         // storage-> gives a pointer to MyCustomStruct instance,
         // created dynamically by the running task tree.
         storage->data = task.reply()->readAll();
     };
     const auto onSecondSetup = [storage](QThreadFunction<QImage> &task) {
         // storage-> gives a pointer to MyCustomStruct. Since the group is sequential,
         // the stored MyCustomStruct was already updated inside the onFirstDone handler.
         const QByteArray storedData = storage->data;
     };

     const Group group {
         // When the group is entered by a running task tree, it creates MyCustomStruct
         // instance dynamically. It is later accessible from all handlers via
         // the *storage or storage-> operators.
         sequential,
         storage,
         QNetworkReplyWrapperTask(onFirstSetup, onFirstDone, CallDoneFlag::OnSuccess),
         QThreadFunctionTask<QImage>(onSecondSetup)
     };

## Member Function Documentation

### Group::Group(const QtTaskTree::GroupItems &children)

Constructs a group with a given list of children.

This constructor is useful when the child items of the group are not known at compile time, but later, at runtime:

     const QStringList sourceList = ...;

     GroupItems groupItems { parallel };

     for (const QString &source : sourceList) {
         const QNetworkReplyWrapperTask task(...); // use source for setup handler
         groupItems << task;
     }

     const Group group(groupItems);

### Group::Group(std::initializer_list<QtTaskTree::GroupItem> children)

Constructs a group from `std::initializer_list` given by children.

This constructor is useful when all child items of the group are known at compile time:

     const Group group {
         finishAllAndSuccess,
         QNetworkReplyWrapperTask(...),
         Group {
             QNetworkReplyWrapperTask(...),
             Group {
                 parallel,
                 QNetworkReplyWrapperTask(...),
                 QNetworkReplyWrapperTask(...),
             }
             QThreadFunctionTask<QString>(...)
         }
     };