QtTaskTree::When Class

class QtTaskTree::When

An element delaying the execution of a body until barrier advance. More...

Header: #include <qbarriertask.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
Since: Qt 6.11
Status: Technical Preview

Note: All functions in this class are reentrant.

Public Functions

When(const QtTaskTree::QCustomTask<Task, Adapter, Deleter> &customTask, Signal signal, QtTaskTree::WorkflowPolicy policy = QtTaskTree::WorkflowPolicy::StopOnError)

Detailed Description

When is used to delay the execution of a Do body until related QStoredBarrier is advanced or until QCustomTask's signal is emitted. It is used in conjunction with Do element like: When () >> Do {}.

See also Do.

Member Function Documentation

[explicit] template < typename Task, typename Adapter, typename Deleter, typename Signal > When::When(const QtTaskTree::QCustomTask<Task, Adapter, Deleter> &customTask, Signal signal, QtTaskTree::WorkflowPolicy policy = QtTaskTree::WorkflowPolicy::StopOnError)

Creates a delaying element, taking customTask and its Task's signal to be run in parallel with a Do body. The Do body is delayed until the Task's signal is emitted. The customTask and the Do body will run in parallel using the policy.

The code from the other When's constructor could be simplified to:

 const auto onSetup = [barrier](QProcess &process) {
     ... // Setup process program, arguments, environment, etc...
 };

 const Group recipe {
     When (QProcessTask(onSetup), &QProcess::started) >> Do {
         delayedTask1,
         ...
     }
 };

Note: The Task type of the passed customTask needs to be derived from QObject.

See also Do.