QFutureWatcher Class

The QFutureWatcher class allows monitoring a QFuture using signals and slots. More...

Header: #include <QFutureWatcher>
qmake: QT += core
Since: Qt 4.4
Inherits: QFutureWatcherBase

Note: All functions in this class are reentrant.

Public Functions

QFutureWatcher(QObject *_parent = nullptr)
~QFutureWatcher()
QFuture<T> future() const
bool isCanceled() const
bool isFinished() const
bool isPaused() const
bool isRunning() const
bool isStarted() const
int progressMaximum() const
int progressMinimum() const
QString progressText() const
int progressValue() const
T result() const
T resultAt(int index) const
void setFuture(const QFuture<T> &future)
void setPendingResultsLimit(int limit)
void waitForFinished()

Public Slots

void cancel()
void pause()
void resume()
void setPaused(bool paused)
void togglePaused()

Signals

void canceled()
void finished()
void paused()
void progressRangeChanged(int minimum, int maximum)
void progressTextChanged(const QString &progressText)
void progressValueChanged(int progressValue)
void resultReadyAt(int resultIndex)
void resultsReadyAt(int beginIndex, int endIndex)
void resumed()
void started()

Additional Inherited Members

Detailed Description

The QFutureWatcher class allows monitoring a QFuture using signals and slots.

QFutureWatcher provides information and notifications about a QFuture. Use the setFuture() function to start watching a particular QFuture. The future() function returns the future set with setFuture().

For convenience, several of QFuture's functions are also available in QFutureWatcher: progressValue(), progressMinimum(), progressMaximum(), progressText(), isStarted(), isFinished(), isRunning(), isCanceled(), isPaused(), waitForFinished(), result(), and resultAt(). The cancel(), setPaused(), pause(), resume(), and togglePaused() functions are slots in QFutureWatcher.

Status changes are reported via the started(), finished(), canceled(), paused(), resumed(), resultReadyAt(), and resultsReadyAt() signals. Progress information is provided from the progressRangeChanged(), void progressValueChanged(), and progressTextChanged() signals.

Throttling control is provided by the setPendingResultsLimit() function. When the number of pending resultReadyAt() or resultsReadyAt() signals exceeds the limit, the computation represented by the future will be throttled automatically. The computation will resume once the number of pending signals drops below the limit.

Example: Starting a computation and getting a slot callback when it's finished:

 // Instantiate the objects and connect to the finished signal.
 MyClass myObject;
 QFutureWatcher<int> watcher;
 connect(&watcher, &QFutureWatcher<int>::finished, &myObject, &MyClass::handleFinished);

 // Start the computation.
 QFuture<int> future = QtConcurrent::run(...);
 watcher.setFuture(future);

Be aware that not all running asynchronous computations can be canceled or paused. For example, the future returned by QtConcurrent::run() cannot be canceled; but the future returned by QtConcurrent::mappedReduced() can.

QFutureWatcher<void> is specialized to not contain any of the result fetching functions. Any QFuture<T> can be watched by a QFutureWatcher<void> as well. This is useful if only status or progress information is needed; not the actual result data.

See also QFuture and Qt Concurrent.

Member Function Documentation

QFutureWatcher::QFutureWatcher(QObject *_parent = nullptr)

Default constructs an instance of QFutureWatcher.

QFutureWatcher::~QFutureWatcher()

Destroys the instance of QFutureWatcher.

[slot] void QFutureWatcher::cancel()

[signal] void QFutureWatcher::canceled()

[signal] void QFutureWatcher::finished()

QFuture<T> QFutureWatcher::future() const

See also setFuture().

bool QFutureWatcher::isCanceled() const

bool QFutureWatcher::isFinished() const

bool QFutureWatcher::isPaused() const

bool QFutureWatcher::isRunning() const

bool QFutureWatcher::isStarted() const

[slot] void QFutureWatcher::pause()

[signal] void QFutureWatcher::paused()

See also setPaused().

int QFutureWatcher::progressMaximum() const

int QFutureWatcher::progressMinimum() const

[signal] void QFutureWatcher::progressRangeChanged(int minimum, int maximum)

QString QFutureWatcher::progressText() const

[signal] void QFutureWatcher::progressTextChanged(const QString &progressText)

int QFutureWatcher::progressValue() const

[signal] void QFutureWatcher::progressValueChanged(int progressValue)

T QFutureWatcher::result() const

T QFutureWatcher::resultAt(int index) const

[signal] void QFutureWatcher::resultReadyAt(int resultIndex)

[signal] void QFutureWatcher::resultsReadyAt(int beginIndex, int endIndex)

[slot] void QFutureWatcher::resume()

[signal] void QFutureWatcher::resumed()

void QFutureWatcher::setFuture(const QFuture<T> &future)

See also future().

[slot] void QFutureWatcher::setPaused(bool paused)

See also paused().

void QFutureWatcher::setPendingResultsLimit(int limit)

[signal] void QFutureWatcher::started()

[slot] void QFutureWatcher::togglePaused()

void QFutureWatcher::waitForFinished()