The QFutureSynchronizer class is a convenience class that simplifies QFuture synchronization. 更多...
头: | #include <QFutureSynchronizer> |
CMake: |
find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
QFutureSynchronizer (const QFuture<T> & future ) | |
QFutureSynchronizer () | |
~QFutureSynchronizer () | |
void | addFuture (const QFuture<T> & future ) |
bool | cancelOnWait () const |
void | clearFutures () |
QList<QFuture<T> > | futures () const |
void | setCancelOnWait (bool enabled ) |
void | setFuture (const QFuture<T> & future ) |
void | waitForFinished () |
QFutureSynchronizer is a template class that simplifies synchronization of one or more QFuture objects. Futures are added using the addFuture () 或 setFuture () 函数。 futures () function returns a list of futures. Use clearFutures () to remove all futures from the QFutureSynchronizer.
waitForFinished () function waits for all futures to finish. The destructor of QFutureSynchronizer calls waitForFinished (), providing an easy way to ensure that all futures have finished before returning from a function:
void someFunction() { QFutureSynchronizer<void> synchronizer; ... synchronizer.addFuture(QtConcurrent::run(anotherFunction)); synchronizer.addFuture(QtConcurrent::map(list, mapFunction)); return; // QFutureSynchronizer waits for all futures to finish }
行为在 waitForFinished () can be changed using the setCancelOnWait () function. Calling setCancelOnWait (true) will cause waitForFinished () to cancel all futures before waiting for them to finish. You can query the status of the cancel-on-wait feature using the cancelOnWait () 函数。
另请参阅 QFuture , QFutureWatcher ,和 Qt Concurrent .
Constructs a QFutureSynchronizer and begins watching future 通过调用 addFuture ().
另请参阅 addFuture ().
Constructs a QFutureSynchronizer.
调用 waitForFinished () function to ensure that all futures have finished before destroying this QFutureSynchronizer .
另请参阅 waitForFinished ().
添加 future to the list of managed futures.
另请参阅 futures ().
返回
true
if the cancel-on-wait feature is enabled; otherwise returns false. If cancel-on-wait is enabled, the
waitForFinished
() function will cancel all futures before waiting for them to finish.
另请参阅 setCancelOnWait () 和 waitForFinished ().
Removes all managed futures from this QFutureSynchronizer .
另请参阅 addFuture () 和 setFuture ().
Returns a list of all managed futures.
另请参阅 addFuture () 和 setFuture ().
Enables or disables the cancel-on-wait feature based on the enabled argument. If enabled is true, the waitForFinished () function will cancel all futures before waiting for them to finish.
另请参阅 cancelOnWait () 和 waitForFinished ().
设置 future to be the only future managed by this QFutureSynchronizer . This is a convenience function that calls waitForFinished (),然后 clearFutures (), and finally passes future to addFuture ().
另请参阅 addFuture (), waitForFinished (),和 clearFutures ().
Waits for all futures to finish. If
cancelOnWait
() 返回
true
, each future is canceled before waiting for them to finish.
另请参阅 cancelOnWait () 和 setCancelOnWait ().