6.0.0-rc4Source

QFutureInterface Class

template <typename T> class QFutureInterface

The QFutureInterface class allows the compution to report its state and results to a QFuture. More…

Header#include <QFutureInterface>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
InheritsQFutureInterfaceBase

List of all members, including inherited members

Public Functions

QFutureInterface(State initialState = NoState)
QFutureInterface(const QFutureInterfaceBase &dd)
QFutureInterface(const QFutureInterface &other)
QFutureInterface(QFutureInterface &&other)
QFutureInterface &operator=(const QFutureInterface &other)
QFutureInterface &operator=(QFutureInterface &&other)
~QFutureInterface()
QFuture<T>future()
boolreportResult(const T *result, int index = -1)
boolreportResult(const T &result, int index = -1)
boolreportAndMoveResult(T &&result, int index = -1)
boolreportAndEmplaceResult(int index, Args &&...args)
boolreportResults(const QList<T> &results, int beginIndex = -1)
voidreportFinished(const T *result)
voidreportFinished()
const T &resultReference(int index) const
boolresultPointer(int index, const T **pointer) const
Tresult() const
QList<T>results()
TtakeResult()

Static Public Members

QFutureInterfacecanceledResult()

Detailed Description

QFutureInterface is the base that QFuture is built on, and the older way to write a computation; QPromise is the one to prefer. An interface and the futures that it makes share the state of the computation, and the results are freed when the last of them goes. Every function can be called from any thread.

See also QPromise, QFuture and QFutureInterfaceBase.

Differences from Qt

The interface has no reportResults() with a count of results and no filter mode. A result that is reported while the future is canceled or finished is dropped and reported as such by the return value.

Member Function Documentation

QFutureInterface::QFutureInterface(State initialState = NoState)

Constructs an interface in the state initialState.

[explicit] QFutureInterface::QFutureInterface(const QFutureInterfaceBase &dd)

Constructs an interface that shares the state of dd, which must come from a QFutureInterface of the same result type.

QFutureInterface::QFutureInterface(const QFutureInterface &other)

Constructs an interface that shares its state with other.

QFutureInterface::QFutureInterface(QFutureInterface &&other)

Moves the state of other into this interface. other can only be destroyed or assigned to afterwards.

[override] QFutureInterface::~QFutureInterface()

Destroys the interface. The results are freed with the last interface or future that shares the state.

[static] QFutureInterface QFutureInterface::canceledResult()

Returns an interface in the state of a canceled and finished computation without results. A default-constructed QFuture uses it.

QFuture<T> QFutureInterface::future()

Returns a future that observes the state of this interface.

QFutureInterface & QFutureInterface::operator=(const QFutureInterface &other)

Shares the state of other with this interface and returns a reference to it.

QFutureInterface & QFutureInterface::operator=(QFutureInterface &&other)

Moves the state of other into this interface and returns a reference to it.

template <typename... Args>bool QFutureInterface::reportAndEmplaceResult(int index, Args &&...args)

Constructs a result from args in the future at index, or after the last result if index is -1. Returns false if the result was not stored.

bool QFutureInterface::reportAndMoveResult(T &&result, int index = -1)

Moves result into the future at index, or after the last result if index is -1. Returns false if the result was not stored.

void QFutureInterface::reportFinished(const T *result)

Reports result, if it is not nullptr, as the last result, and then finishes the computation.

void QFutureInterface::reportFinished()

Finishes the computation.

bool QFutureInterface::reportResult(const T *result, int index = -1)

Copies result into the future at index, or after the last result if index is -1, and returns true. Returns false, and drops result, if the future is finished or canceled, if result is nullptr or if there already is a result at index.

bool QFutureInterface::reportResult(const T &result, int index = -1)

This is an overloaded function.

Copies result into the future at index.

bool QFutureInterface::reportResults(const QList<T> &results, int beginIndex = -1)

Copies results into the future, starting at beginIndex or after the last result if it is -1. All of them become available together. Returns false if they were not stored.

T QFutureInterface::result() const

Waits for the first result and returns a copy of it. Returns a default-constructed value if the computation ends without one. Throws the exception that the computation ended with, if any.

bool QFutureInterface::resultPointer(int index, const T **pointer) const

Returns true if the result at index exists, and stores a pointer to it in pointer; otherwise returns false.

const T & QFutureInterface::resultReference(int index) const

Returns a reference to the result at index, which must be available; see waitForResult() and isResultReadyAt(). The reference stays valid as long as the future shares this state.

QList<T> QFutureInterface::results()

Waits for the computation to finish and returns a copy of all results. Returns an empty list if the computation was canceled. Throws the exception that the computation ended with, if any.

T QFutureInterface::takeResult()

Waits for the first result and moves it out of the future. The result is left in its moved-from state, so no other consumer should read it.