|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QFuture
public class QFuture
The QFuture
class represents the result of an asynchronous computation. To start a computation, use one of the APIs in the Qt Concurrent framework.
QFuture
allows threads to be synchronized against one or more results which will be ready at a later point in time. The result can be of any type that has a default constructor and a copy constructor. If a result is not available at the time of calling the result()
, resultAt()
, or results()
functions, QFuture
will wait until the result becomes available. You can use the isResultReadyAt()
function to determine if a result is ready or not. For QFuture
objects that report more than one result, the resultCount()
function returns the number of continuous results. This means that it is always safe to iterate through the results from 0 to resultCount()
.
QFuture
provides a Java-style iterator (QFutureIterator
) and an STL-style iterator (QFuture::const_iterator). Using these iterators is another way to access results in the future.
QFuture
also offers ways to interact with a runnning computation. For instance, the computation can be canceled with the cancel()
function. To pause the computation, use the setPaused()
function or one of the pause()
, resume()
, or togglePaused()
convenience functions. 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.
Progress information is provided by the progressValue()
, progressMinimum()
, progressMaximum()
, and progressText()
functions. The waitForFinished()
function causes the calling thread to block and wait for the computation to finish, ensuring that all results are available.
The state of the computation represented by a QFuture
can be queried using the isCanceled()
, isStarted()
, isFinished()
, isRunning()
, or isPaused()
functions.
QFuture
is a lightweight reference counted class that can be passed by value.
QFuture
<void> is specialized to not contain any of the result fetching functions. Any QFuture
<T> can be assigned or copied into a QFuture
<void> as well. This is useful if only status or progress information is needed - not the actual result data.
To interact with running tasks using signals and slots, use QFutureWatcher
.
QFutureWatcher
, and Qt Concurrent.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QFuture()
Constructs an empty future. |
|
QFuture(QFuture other)
Constructs a copy of other. |
Method Summary | |
---|---|
void |
cancel()
Cancels the asynchronous computation represented by this future. |
QFuture |
clone()
This method is reimplemented for internal reasons |
static QFuture |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
isCanceled()
Returns true if the asynchronous computation has been canceled with the cancel() function; otherwise returns false. |
boolean |
isFinished()
Returns true if the asynchronous computation represented by this future has finished; otherwise returns false. |
boolean |
isPaused()
Returns true if the asynchronous computation has been paused with the pause() function; otherwise returns false. |
boolean |
isResultReadyAt(int index)
Returns true if the result at index is immediately available; otherwise returns false. |
boolean |
isRunning()
Returns true if the asynchronous computation represented by this future is currently running; otherwise returns false. |
boolean |
isStarted()
Returns true if the asynchronous computation represented by this future has been started; otherwise returns false. |
static QNativePointer |
nativePointerArray(QFuture[] array)
|
void |
pause()
Pauses the asynchronous computation represented by this future. |
int |
progressMaximum()
Returns the maximum progressValue() . |
int |
progressMinimum()
Returns the minimum progressValue() . |
java.lang.String |
progressText()
Returns the (optional) textual representation of the progress as reported by the asynchronous computation. |
int |
progressValue()
Returns the current progress value, which is between the progressMinimum() and progressMaximum() . |
java.lang.Object |
result()
Returns the first result in the future. |
java.lang.Object |
resultAt(int index)
Returns the result at index in the future. |
int |
resultCount()
Returns the number of continuous results available in this future. |
java.util.List |
results()
Returns all results from the future. |
void |
resume()
Resumes the asynchronous computation represented by this future. |
void |
setPaused(boolean paused)
If paused is true, this function pauses the asynchronous computation represented by the future. |
void |
togglePaused()
Toggles the paused state of the asynchronous computation. |
void |
waitForFinished()
Waits for the asynchronous computation to finish (including cancel() ed computations). |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QFuture()
public QFuture(QFuture other)
Method Detail |
---|
public final void cancel()
waitForFinished()
after calling cancel()
when you need synchronous cancelation. Results currently available may still be accessed on a canceled future, but new results will not become available after calling this function. Any QFutureWatcher
object that is watching this future will not deliver progress and result ready signals on a canceled future.
Be aware that not all asynchronous computations can be canceled. For example, the future returned by QtConcurrent::run() cannot be canceled; but the future returned by QtConcurrent::mappedReduced() can.
public final boolean isCanceled()
cancel()
function; otherwise returns false. Be aware that the computation may still be running even though this function returns true. See cancel()
for more details.
public final boolean isFinished()
public final boolean isPaused()
pause()
function; otherwise returns false. Be aware that the computation may still be running even though this function returns true. See setPaused()
for more details.
setPaused()
, and togglePaused()
.
public final boolean isResultReadyAt(int index)
resultAt()
, and resultCount()
.
public final boolean isRunning()
public final boolean isStarted()
public final void pause()
setPaused
(true). resume()
.
public final int progressMaximum()
progressValue()
. progressValue()
, and progressMinimum()
.
public final int progressMinimum()
progressValue()
. progressValue()
, and progressMaximum()
.
public final java.lang.String progressText()
Be aware that not all computations provide a textual representation of the progress, and as such, this function may return an empty string.
public final int progressValue()
progressMinimum()
and progressMaximum()
. progressMinimum()
, and progressMaximum()
.
public final java.lang.Object result()
resultAt
(0). resultAt()
, and results()
.
public final java.lang.Object resultAt(int index)
result()
, results()
, and resultCount()
.
public final int resultCount()
resultCount()
. result()
, resultAt()
, and results()
.
public final java.util.List results()
result()
, resultAt()
, and resultCount()
.
public final void resume()
setPaused
(false). pause()
.
public final void setPaused(boolean paused)
QFutureWatcher
object that is watching this future will stop delivering progress and result ready signals while the future is paused. Signal delivery will continue once the future is resumed. If paused is false, this function resumes the asynchronous computation. If the computation was not previously paused, this function does nothing.
Be aware that not all computations can be paused. For example, the future returned by QtConcurrent::run() cannot be paused; but the future returned by QtConcurrent::mappedReduced() can.
isPaused()
, pause()
, resume()
, and togglePaused()
.
public final void togglePaused()
setPaused
(!isPaused()
). setPaused()
, pause()
, and resume()
.
public final void waitForFinished()
cancel()
ed computations).
public static QFuture fromNativePointer(QNativePointer nativePointer)
public static QNativePointer nativePointerArray(QFuture[] array)
public QFuture clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |