QtTaskTree::QSyncTask Class | Qt TaskTree | Qt 6.11.2
Description: Synchronously executes a custom handler between other tasks.

- Qt 6.11
- Qt TaskTree
- C++ Classes
- QSyncTask
- Qt 6.11.2 Reference Documentation

# QtTaskTree::QSyncTask Class

class QtTaskTree::QSyncTask

Synchronously executes a custom handler between other 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

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| QSyncTask(Handler &&handler)

## Detailed Description

QSyncTask is useful when you want to execute an additional handler between other tasks. QSyncTask is seen by its parent Group as any other task. Avoid long-running execution of the QSyncTask's handler body, since it is executed synchronously from the caller thread. If that is unavoidable, consider using QThreadFunctionTask instead.

## Member Function Documentation

### `[explicit]` template <typename Handler, std::enable_if_t<!std::is_same_v<q20::remove_cvref_t<Handler>, QSyncTask>, bool> = true> QSyncTask::QSyncTask(Handler &&handler)

Constructs an element that executes a passed handler synchronously. The `Handler` is of the `std::function<DoneResult()>` type. The DoneResult value, returned by the handler, is considered during parent group's workflow policy resolution. Optionally, the shortened form of `std::function<void()>` is also accepted. In this case, it's assumed that the return value is DoneResult::Success.

The passed handler executes synchronously from the caller thread, so avoid a long-running execution of the handler body. Otherwise, consider using QThreadFunctionTask.

Note: The QSyncTask element is not counted as a task when reporting task tree progress, and is not included in QTaskTree::taskCount() or QTaskTree::progressMaximum().