Loading...
Searching...
No Matches
QXmppTask< T > Class Template Reference
Core classes

`#include <QXmppTask.h>`

## Public Member Functions

void | then (const QObject *context, Continuation continuation)
bool | isFinished () const
bool | hasResult () const
const T & | result () const
T | takeResult ()
QFuture< T > | toFuture (const QObject *context)

## Friends

class | QXmppPromise< T >

## Detailed Description

template<typename T>
class QXmppTask< T >

Handle for an ongoing operation that finishes in the future.

Tasks are generated by QXmppPromise and can be handled using QXmppTask::then().

Unlike QFuture, this is not thread-safe. This avoids the need to do mutex locking at every access though.

Since
  QXmpp 1.5

## Member Function Documentation

## hasResult()

template<typename T >

bool QXmppTask< T >::hasResult | ( |  | ) | const

inline

Returns whether the task is finished and the value has not been taken yet.

## isFinished()

template<typename T >

bool QXmppTask< T >::isFinished | ( |  | ) | const

inline

Whether the asynchronous operation is already finished.

This does not mean that the result is still stored, it might have been taken using takeResult() or handled using then().

## result()

template<typename T >

const T & QXmppTask< T >::result | ( |  | ) | const

inline

The result of the operation.

Warning
  This can only be used once the operation is finished.

## takeResult()

template<typename T >

T QXmppTask< T >::takeResult | ( |  | ) |

inline

Moves the result of the operation out of the task.

Warning
  This can only be used once and only after the operation has finished.

## then()

template<typename T >

void QXmppTask< T >::then | ( | const QObject * | context,
|  | Continuation | continuation
| ) |  |

inline

Registers a function that will be called with the result as parameter when the asynchronous operation finishes.

If the task is already finished when calling this (and still has a result), the function will be called immediately.

If another function was previously registered using .then(), the old function will be replaced, and only the new one will be called.

Example usage:

QXmppTask<QString> generateSomething();
void Manager::generate()
{
generateSomething().then(this, [](QString &&result) {
// runs as soon as the result is finished
qDebug() << "Generating finished:" << result;
});
// The generation could still be in progress here and the lambda might not
// have been executed yet.
}
// Manager is derived from QObject.
QXmppTask
Definition QXmppTask.h:62
QXmppTask::result
const T & result() const
Definition QXmppTask.h:162

Parameters

  context | QObject used for unregistering the handler function when the object is deleted. This way your lambda will never be executed after your object has been deleted.
  continuation | A function accepting a result in the form of `T &&`.

## toFuture()

template<typename T >

QFuture< T > QXmppTask< T >::toFuture | ( | const QObject * | context | ) |

inline

Converts the Task into a QFuture. Afterwards the QXmppTask object is invalid.

The documentation for this class was generated from the following file:

- QXmppTask.h