このページでは

QtTaskTree::If Class

class QtTaskTree::If

条件式で使われる "if "要素。詳細...

ヘッダ #include <qconditional.h>
CMakeで使用される "if "要素: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
以来:Qt 6.11

注意:このクラスの関数はすべてリエントラントです。

パブリック関数

If(const QtTaskTree::ExecutableItem &condition)
If(Handler &&handler)

詳細説明

条件式の初期条件要素。常にThen 要素が続かなければならない。

TaskTree モジュールの条件式は、分岐条件とその本体を非同期で処理できるようにします。例えば

const Group recipe {
    If (conditionTask1) >> Then {
        bodyTask1
    } >> ElseIf (conditionTask2) >> Then {
        bodyTask2
    } >> Else {
        bodyTask3
    }
};

上記のレシピがQTaskTree で実行されると、タスクツリーはまず非同期のconditionTask1 を開始する。それが終了した後、その結果に応じて、タスクツリーはconditionTask1 が成功裏に終了した場合はbodyTask1 を実行し、そうでない場合はconditionTask2 を実行して別の条件をディスパッチします。bodyTask1 が実行された場合、他のタスクは実行されず、bodyTask1 の結果が条件式全体の最終結果となる。

ThenElseElseIfも参照のこと

メンバ関数ドキュメント

[explicit] If::If(const QtTaskTree::ExecutableItem &condition)

条件式で使用するcondition タスクの初期条件要素を作成する。実行中のQTaskTree は、渡されたcondition を最初に実行し、終了後、Then ブランチが実行される(成功した場合)か、オプションで、Else ブランチか、ElseIf 条件が実行される。

渡されたcondition は、Group 要素で囲まれた複数のタスクで構成されたり、それらの接続や論理和で構成されたりします:

const Group subRecipe {
    parallel,
    parallelConditionTask1,
    parallelConditionTask2
};

const Group recipe {
    If (conditionTask1 && !conditionTask2) >> Then {
        bodyTask1
    } >> ElseIf (subRecipe) >> Then {
        bodyTask2
    } >> Else {
        bodyTask3
    }
};

[explicit] template <typename Handler, std::enable_if_t<!std::is_base_of_v<ExecutableItem, std::decay_t<Handler>>, bool> = true> If::If(Handler &&handler)

実行中のQTaskTree で初期条件を評価するときに実行される同期handler を受け付けるヘルパーコンストラクタです。

のショートカットである:

If (QSyncTask(handler))

どのようなハンドラ型が受け入れられるかについての詳細はQSyncTask を参照。

これはオーバーロードされた関数です。

QSyncTask およびElseIfも参照して ください。

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