CopperSpice API  1.9.2
QFutureSynchronizer< T > Class Template Reference

The QFutureSynchronizer class simplifies QFuture synchronization. More...

Public Methods

 QFutureSynchronizer ()
 
 QFutureSynchronizer (const QFuture< T > &future)
 
 ~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 ()
 

Detailed Description

template<typename T>
class QFutureSynchronizer< T >

The QFutureSynchronizer class simplifies QFuture synchronization. This is templated class which synchronizes with one or more QFuture objects. Futures are added using the addFuture() or setFuture() functions. The futures() method returns a list of futures. Use clearFutures() to remove all futures from the QFutureSynchronizer.

The waitForFinished() method 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()
{
// ...
synchronizer.addFuture(QtConcurrent::run(anotherFunction));
synchronizer.addFuture(QtConcurrent::map(list, mapFunction));
return; // QFutureSynchronizer waits for all futures to finish
}

The behavior of 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() function.

See also
QFuture, QFutureWatcher, Concurrent Programming

Constructor & Destructor Documentation

template<typename T >
QFutureSynchronizer< T >::QFutureSynchronizer ( )
inline

Constructs a QFutureSynchronizer.

template<typename T >
QFutureSynchronizer< T >::QFutureSynchronizer ( const QFuture< T > &  future)
inlineexplicit

Constructs a QFutureSynchronizer and begins watching future by calling addFuture().

See also
addFuture()
template<typename T >
QFutureSynchronizer< T >::~QFutureSynchronizer ( )
inline

Calls waitForFinished() function to ensure that all futures have finished before destroying this QFutureSynchronizer.

See also
waitForFinished()

Method Documentation

template<typename T >
void QFutureSynchronizer< T >::addFuture ( const QFuture< T > &  future)
inline

Adds future to the list of managed futures.

See also
futures()
template<typename T >
bool QFutureSynchronizer< T >::cancelOnWait ( ) const
inline

Returns 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.

See also
setCancelOnWait(), waitForFinished()
template<typename T >
void QFutureSynchronizer< T >::clearFutures ( )
inline

Removes all managed futures from this QFutureSynchronizer.

See also
addFuture(), setFuture()
template<typename T >
QList< QFuture< T > > QFutureSynchronizer< T >::futures ( ) const
inline

Returns a list of all managed futures.

See also
addFuture(), setFuture()
template<typename T >
void QFutureSynchronizer< T >::setCancelOnWait ( bool  enabled)
inline

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.

See also
cancelOnWait(), waitForFinished()
template<typename T >
void QFutureSynchronizer< T >::setFuture ( const QFuture< T > &  future)
inline

Sets future to be the only future managed by this QFutureSynchronizer. This method calls waitForFinished(), clearFutures(), and finally passes the given future to addFuture().

See also
addFuture(), waitForFinished(), clearFutures()
template<typename T >
void QFutureSynchronizer< T >::waitForFinished ( )
inline

Waits for all futures to finish. If cancelOnWait() returns true, each future is canceled before waiting for them to finish.

See also
cancelOnWait(), setCancelOnWait()