- Qt 6.9
- Qt Core
- C++ Classes
- QFutureWatcher
- Qt 6.9.2 Reference Documentation

# QFutureWatcher Class

template <typename T> class QFutureWatcher

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

Header: | `#include <QFutureWatcher>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Inherits: | QObject

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Detailed Description

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(), isSuspending(), isSuspended(), waitForFinished(), result(), and resultAt(). The cancel(), setSuspended(), suspend(), resume(), and toggleSuspended() functions are slots in QFutureWatcher.

Status changes are reported via the started(), finished(), canceled(), suspending(), suspended(), 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 suspended. 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.