このページでは

QtTaskTree::Group Class

class QtTaskTree::Group

「グループ」は、非同期タスクの入れ子になったツリーをどのように実行・処理するかを記述する宣言型レシピを構成するための基本要素です。詳細...

ヘッダー: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
以下のように: Qt 6.11
継承元: QtTaskTree::ExecutableItem
ステータス: テクノロジープレビュー

このクラスはテクノロジープレビュー段階にあり、変更される可能性があります。

注:このクラスのすべての関数は再入可能です。

パブリック関数

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

詳細な説明

Group は、他のグループ項目を格納するコンテナです。子タスクを 1 つの単位にまとめ、グループの親からは単一の非同期タスクとして認識されます。Group はGroupItem 型であるため、Group の子となることもできます。

QThreadFunctionTask<ResultType> やQNetworkReplyWrapperTask といった、エイリアス化されたカスタムタスク名を使用して、子タスクをグループに挿入します。

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

ExecutionMode またはWorkflowPolicy アイテムを挿入することで、グループの動作をカスタマイズできます:

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

グループにはネストされたグループを含めることができます:

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

グループは、タスク間のデータ交換に使用できるカスタムストレージ構造体を動的にインスタンス化できます:

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

メンバ関数のドキュメント

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

指定されたchildren のリストを用いてグループを構築します。

このコンストラクタは、グループの子要素がコンパイル時には不明で、実行時に初めて判明する場合に役立ちます:

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)

children で指定されたstd::initializer_list からグループを構築します。

このコンストラクタは、グループのすべての子要素がコンパイル時に既知である場合に役立ちます:

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

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