| 頭: | #include <QFuture> |
| qmake: | QT += core |
| Since: | Qt 4.4 |
注意: 此類的所有函數 綫程安全 除以下外:
| class | const_iterator |
| typedef | ConstIterator |
| QFuture () | |
| QFuture (const QFuture<T> & other ) | |
| ~QFuture () | |
| QFuture::const_iterator | begin () const |
| void | cancel () |
| QFuture::const_iterator | constBegin () const |
| QFuture::const_iterator | constEnd () const |
| QFuture::const_iterator | end () const |
| bool | isCanceled () const |
| bool | isFinished () const |
| bool | isPaused () const |
| bool | isResultReadyAt (int index ) const |
| bool | isRunning () const |
| bool | isStarted () const |
| void | pause () |
| int | progressMaximum () const |
| int | progressMinimum () const |
| QString | progressText () const |
| int | progressValue () const |
| T | result () const |
| T | resultAt (int index ) const |
| int | resultCount () const |
| QList<T> | 結果 () const |
| void | resume () |
| void | setPaused (bool paused ) |
| void | togglePaused () |
| void | waitForFinished () |
| T | operator T () const |
| bool | operator!= (const QFuture<T> & other ) const |
| QFuture<T> & | operator= (const QFuture<T> & other ) |
| bool | operator== (const QFuture<T> & other ) const |
| QFutureInterface<T> | d |
The QFuture 類錶示異步計算的結果。
要開始計算,請使用某一 API 在 Qt Concurrent 框架。
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 (),或 結果 () 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 提供 Java 風格迭代器 ( QFutureIterator ) 和 STL 樣式迭代器 ( 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 (),或 togglePaused () convenience functions. Be aware that not all running 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 (),和 progressText () 函數。 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 (),或 isPaused () 函數。
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 .
Qt 樣式同義詞 QFuture::const_iterator .
構建空的被取消 Future。
構造副本為 other .
另請參閱 operator= ().
銷毀 Future。
Note that this neither waits nor cancels the asynchronous computation. Use waitForFinished () 或 QFutureSynchronizer when you need to ensure that the computation is completed before the future is destroyed.
返迴常量 STL 樣式迭代器 指嚮 Future 的第 1 個結果。
另請參閱 constBegin () 和 end ().
Cancels the asynchronous computation represented by this future. Note that the cancelation is asynchronous. Use 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 running asynchronous computations can be canceled. For example, the future returned by QtConcurrent::run () cannot be canceled; but the future returned by QtConcurrent::mappedReduced () can.
返迴常量 STL 樣式迭代器 指嚮 Future 的第 1 個結果。
返迴常量 STL 樣式迭代器 pointing to the imaginary result after the last result in the future.
另請參閱 constBegin () 和 end ().
返迴常量 STL 樣式迭代器 pointing to the imaginary result after the last result in the future.
返迴
true
if the asynchronous computation has been canceled with the
cancel
() function; otherwise returns
false
.
Be aware that the computation may still be running even though this function returns
true
。見
cancel
() 瞭解更多細節。
返迴
true
if the asynchronous computation represented by this future has finished; otherwise returns
false
.
返迴
true
if the asynchronous computation has been paused with the
pause
() function; otherwise returns
false
.
Be aware that the computation may still be running even though this function returns
true
。見
setPaused
() 瞭解更多細節。
另請參閱 setPaused () 和 togglePaused ().
返迴
true
if the result at
index
is immediately available; otherwise returns
false
.
另請參閱 resultAt () 和 resultCount ().
返迴
true
if the asynchronous computation represented by this future is currently running; otherwise returns
false
.
返迴
true
if the asynchronous computation represented by this future has been started; otherwise returns
false
.
Pauses the asynchronous computation represented by this future. This is a convenience method that simply calls setPaused (true)。
另請參閱 resume ().
返迴最大 progressValue ().
另請參閱 progressValue () 和 progressMinimum ().
返迴最小 progressValue ().
另請參閱 progressValue () 和 progressMaximum ().
Returns the (optional) textual representation of the progress as reported by the asynchronous computation.
Be aware that not all computations provide a textual representation of the progress, and as such, this function may return an empty string.
返迴當前進度值,位於 progressMinimum () 和 progressMaximum ().
另請參閱 progressMinimum () 和 progressMaximum ().
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).
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.
另請參閱 result (), 結果 (),和 resultCount ().
Returns the number of continuous results available in this future. The real number of results stored might be different from this value, due to gaps in the result set. It is always safe to iterate through the results from 0 to resultCount().
另請參閱 result (), resultAt (),和 結果 ().
Returns all results from the future. If the results are not immediately available, this function will block and wait for them to become available.
另請參閱 result (), resultAt (),和 resultCount ().
Resumes the asynchronous computation represented by this future. This is a convenience method that simply calls setPaused (false).
另請參閱 pause ().
若 paused is true, this function pauses the asynchronous computation represented by the future. If the computation is already paused, this function does nothing. Any 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.
若 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 (),和 togglePaused ().
Toggles the paused state of the asynchronous computation. In other words, if the computation is currently paused, calling this function resumes it; if the computation is running, it is paused. This is a convenience method for calling setPaused (! isPaused ()).
另請參閱 setPaused (), pause (),和 resume ().
Waits for the asynchronous computation to finish (including cancel ()ed computations).
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 result () 或 resultAt (0).
另請參閱 result (), resultAt (),和 結果 ().
返迴
true
if
other
is
not
a copy of this future; otherwise returns false.
賦值 other to this future and returns a reference to this future.
返迴
true
if
other
是此未來的副本;否則返迴
false
.