com.trolltech.qt.core
Class QFutureWatcher<T>

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.core.QFutureWatcherBase
                  extended by com.trolltech.qt.core.QFutureWatcher<T>
All Implemented Interfaces:
QtJambiInterface

public class QFutureWatcher<T>
extends QFutureWatcherBase

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:

The following code example is written in c++.

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

    // Start the computation.
    QFuture<int> future = QtConcurrent::run(...);
    watcher.setFuture(future);
Be aware that not all 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.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QtJambiObject
QtJambiObject.QPrivateConstructor
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.core.QFutureWatcherBase
canceled, finished, paused, progressRangeChanged, progressTextChanged, progressValueChanged, resultReadyAt, resultsReadyAt, resumed, started
 
Constructor Summary
  QFutureWatcher()
          Constructs a new QFutureWatcher with the given parent.
  QFutureWatcher(QObject _parent)
          Constructs a new QFutureWatcher with the given parent.
protected QFutureWatcher(QtJambiObject.QPrivateConstructor p)
          This method is internal to Qt Jambi.
 
Method Summary
static QFutureWatcher fromNativePointer(QNativePointer nativePointer)
          This method returns the QFutureWatcher instance pointed to by nativePointer.
 QFuture<T> future()
          Returns the watched future.
 T result()
          Returns the first result in the future().
 T resultAt(int index)
          Returns the result at index in the future().
 void setFuture(QFuture<T> future)
          Starts watching the given future.
 
Methods inherited from class com.trolltech.qt.core.QFutureWatcherBase
__qt_signalInitialization, cancel, connectOutputInterface, disconnectOutputInterface, disconnectOutputInterface, event, isCanceled, isFinished, isPaused, isRunning, isStarted, pause, progressMaximum, progressMinimum, progressText, progressValue, resume, setPaused, setPendingResultsLimit, togglePaused, waitForFinished
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
disableGarbageCollection, dispose, disposed, equals, finalize, nativeId, nativePointer, reassignNativeResources, reenableGarbageCollection, setJavaOwnership, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QFutureWatcher

public QFutureWatcher()
Constructs a new QFutureWatcher with the given parent.


QFutureWatcher

public QFutureWatcher(QObject _parent)
Constructs a new QFutureWatcher with the given parent.


QFutureWatcher

protected QFutureWatcher(QtJambiObject.QPrivateConstructor p)
This method is internal to Qt Jambi.

Method Detail

result

public final T result()
Returns the first result in the future(). If the result is not immediately available, this function will block and wait for the result to become available. This is a convenience method for calling resultAt(0).

See also:
resultAt().


resultAt

public final T resultAt(int index)
Returns the result at index in the future(). If the result is not immediately available, this function will block and wait for the result to become available.

See also:
result().


setFuture

public final void setFuture(QFuture<T> future)
Starts watching the given future.

See also:
future().


fromNativePointer

public static QFutureWatcher fromNativePointer(QNativePointer nativePointer)
This method returns the QFutureWatcher instance pointed to by nativePointer.


future

public final QFuture<T> future()
Returns the watched future.

See also:
setFuture().