- Extending Qt Creator Manual
- QtTaskTree
- Group
- Extending Qt Creator Manual 21.0.0-beta1

# 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: | 6.11
Inherits: | QtTaskTree::ExecutableItem

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## 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)
     };