- Extending Qt Creator Manual
- TaskTree
- QBarrier
- Extending Qt Creator Manual 19.0.0-beta1

# QBarrier Class

An asynchronous task that finishes on demand. More...

Header: | `#include <qbarriertask.h>`
Inherits: | QObject
Inherited By: | QStartedBarrier

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

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

## Signals

void | done(QtTaskTree::DoneResult result)

## 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

### QBarrier::QBarrier(QObject *parent = nullptr)

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.

### int 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.

### bool QBarrier::isRunning() const

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

### int 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(int 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.