QtTaskTree::QBarrier Class | Qt TaskTree | Qt 6.11.0
Description: An asynchronous task that finishes on demand.

- Qt 6.11
- Qt TaskTree
- C++ Classes
- QtTaskTree (Technical Preview)
- QBarrier
- Qt 6.11.0 Reference Documentation

# QtTaskTree::QBarrier Class

class QtTaskTree::QBarrier

An asynchronous task that finishes on demand. 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
Inherits: | QObject
Inherited By: | QtTaskTree::QStartedBarrier
Status: | Technical Preview

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| QBarrier(QObject *parent)
void | advance()
qsizetype | current() const
bool | isRunning() const
qsizetype | limit() const
std::optional<QtTaskTree::DoneResult> | result() const
void | setLimit(qsizetype value)
void | start()
void | stopWithResult(QtTaskTree::DoneResult result)

## Signals

void | done(QtTaskTree::DoneResult result)

## Reimplemented Protected Functions

virtual bool | event(QEvent *event) override

## Detailed Description

QBarrier waits for subsequent calls to advance() to reach the barrier's limit (1 by default). It finishes with DoneResult::Success.

It's often used in QTaskTree recipes to hold the execution of subsequent sequential tasks until some other running task delivers some data which are needed to setup the subsequent tasks.

## Member Function Documentation

### `[explicit]` QBarrier::QBarrier(QObject *parent)

Constructs a QBarrier with a given parent.

### void QBarrier::advance()

Advances the barrier. If the number of calls to advance() reaches the barrier's limit, the barrier finishes with DoneResult::Success.

### qsizetype QBarrier::current() const

Returns the current advance count of the barrier.

### `[private signal]` void QBarrier::done(QtTaskTree::DoneResult result)

This signal is emitted when the barrier finished, passing the final result of the execution.

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

### `[override virtual protected]` bool QBarrier::event(QEvent *event)

Reimplements: QObject::event(QEvent *e).

### bool QBarrier::isRunning() const

Returns `true` if the barrier is currently running; otherwise returns `false`.

### qsizetype QBarrier::limit() const

Returns the current limit of the barrier.

See also setLimit().

### std::optional<QtTaskTree::DoneResult> QBarrier::result() const

Returns the result of barrier execution. If barrier wasn't started or it's still running, the returned optional is empty. Otherwise, it returns the result of the last execution.

### void QBarrier::setLimit(qsizetype value)

Sets the limit to value. After it is started, the barrier finishes when the number of calls to advance() reaches the limit.

See also limit().

### void QBarrier::start()

Starts the barrier.

### void QBarrier::stopWithResult(QtTaskTree::DoneResult result)

Stops the running barrier unconditionally with a given result. The barrier's limit is ignored.