Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
26 captures
03 Jan 2013 - 07 Sep 2025
MarJUNOct
Previous capture01Next capture
201220132014
success
fail
COLLECTED BY
Organization:Internet Archive
The Internet Archive discovers and captures web pages through many different web crawls.At any given time several distinct crawls are running, some for months, and some every day or longer.View the web archive through theWayback Machine.
Web wide crawl with initial seedlist and crawler configuration from April 2013.
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20130601062401/http://qt-project.org/doc/qt-5.0/qtcore/qfuture.html
Home
Qt Project
 

QFuture Class

The QFuture class represents the result of an asynchronous computation.More...

#include <QFuture>

Note: All functions in this class arethread-safe, except forconst_iterator, which is onlyreentrant.

This class was introduced in QtCore 4.4.

Public Types

classconst_iterator
typedefConstIterator

Public Functions

QFuture()
QFuture(const QFuture & other)
~QFuture()
const_iteratorbegin() const
voidcancel()
const_iteratorconstBegin() const
const_iteratorconstEnd() const
const_iteratorend() const
boolisCanceled() const
boolisFinished() const
boolisPaused() const
boolisResultReadyAt(int index) const
boolisRunning() const
boolisStarted() const
voidpause()
intprogressMaximum() const
intprogressMinimum() const
QStringprogressText() const
intprogressValue() const
Tresult() const
TresultAt(int index) const
intresultCount() const
QList<T>results() const
voidresume()
voidsetPaused(bool paused)
voidtogglePaused()
voidwaitForFinished()
operator T() const
booloperator!=(const QFuture & other) const
QFuture &operator=(const QFuture & other)
booloperator==(const QFuture & other) const

Detailed Description

The QFuture class represents the result of an asynchronous computation.

To start a computation, use one of the APIs in theQt 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 theresult(),resultAt(), orresults() functions, QFuture will wait until the result becomes available. You can use theisResultReadyAt() function to determine if a result is ready or not. For QFuture objects that report more than one result, theresultCount() function returns the number of continuous results. This means that it is always safe to iterate through the results from 0 toresultCount().

QFuture provides aJava-style iterator (QFutureIterator) and anSTL-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 thecancel() function. To pause the computation, use thesetPaused() function or one of thepause(),resume(), ortogglePaused() 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 theprogressValue(),progressMinimum(),progressMaximum(), andprogressText() functions. ThewaitForFinished() 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 theisCanceled(),isStarted(),isFinished(),isRunning(), orisPaused() 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, useQFutureWatcher.

See alsoQFutureWatcher andQt Concurrent.

Member Type Documentation

typedef QFuture::ConstIterator

Qt-style synonym forQFuture::const_iterator.

Member Function Documentation

QFuture::QFuture()

Constructs an empty future.

QFuture::QFuture(constQFuture & other)

Constructs a copy ofother.

See alsooperator=().

QFuture::~QFuture()

Destroys the future.

Note that this neither waits nor cancels the asynchronous computation. UsewaitForFinished() orQFutureSynchronizer when you need to ensure that the computation is completed before the future is destroyed.

const_iterator QFuture::begin() const

Returns a constSTL-style iterator pointing to the first result in the future.

See alsoconstBegin() andend().

void QFuture::cancel()

Cancels the asynchronous computation represented by this future. Note that the cancelation is asynchronous. UsewaitForFinished() after calling cancel() when you need synchronous cancelation.

Results currently available may still be accessed on a canceled future, but new results willnot become available after calling this function. AnyQFutureWatcher 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.

const_iterator QFuture::constBegin() const

Returns a constSTL-style iterator pointing to the first result in the future.

See alsobegin() andconstEnd().

const_iterator QFuture::constEnd() const

Returns a constSTL-style iterator pointing to the imaginary result after the last result in the future.

See alsoconstBegin() andend().

const_iterator QFuture::end() const

Returns a constSTL-style iterator pointing to the imaginary result after the last result in the future.

See alsobegin() andconstEnd().

bool QFuture::isCanceled() const

Returns true if the asynchronous computation has been canceled with thecancel() function; otherwise returns false.

Be aware that the computation may still be running even though this function returns true. Seecancel() for more details.

bool QFuture::isFinished() const

Returns true if the asynchronous computation represented by this future has finished; otherwise returns false.

bool QFuture::isPaused() const

Returns true if the asynchronous computation has been paused with thepause() function; otherwise returns false.

Be aware that the computation may still be running even though this function returns true. SeesetPaused() for more details.

See alsosetPaused() andtogglePaused().

bool QFuture::isResultReadyAt(int index) const

Returns true if the result atindex is immediately available; otherwise returns false.

See alsoresultAt() andresultCount().

bool QFuture::isRunning() const

Returns true if the asynchronous computation represented by this future is currently running; otherwise returns false.

bool QFuture::isStarted() const

Returns true if the asynchronous computation represented by this future has been started; otherwise returns false.

void QFuture::pause()

Pauses the asynchronous computation represented by this future. This is a convenience method that simply calls setPaused(true).

See alsoresume().

int QFuture::progressMaximum() const

Returns the maximumprogressValue().

See alsoprogressValue() andprogressMinimum().

int QFuture::progressMinimum() const

Returns the minimumprogressValue().

See alsoprogressValue() andprogressMaximum().

QString QFuture::progressText() const

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.

int QFuture::progressValue() const

Returns the current progress value, which is between theprogressMinimum() andprogressMaximum().

See alsoprogressMinimum() andprogressMaximum().

T QFuture::result() const

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 alsoresultAt() andresults().

T QFuture::resultAt(int index) const

Returns the result atindex in the future. If the result is not immediately available, this function will block and wait for the result to become available.

See alsoresult(),results(), andresultCount().

int QFuture::resultCount() const

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().

See alsoresult(),resultAt(), andresults().

QList<T> QFuture::results() const

Returns all results from the future. If the results are not immediately available, this function will block and wait for them to become available.

See alsoresult(),resultAt(), andresultCount().

void QFuture::resume()

Resumes the asynchronous computation represented by this future. This is a convenience method that simply calls setPaused(false).

See alsopause().

void QFuture::setPaused(bool paused)

Ifpaused is true, this function pauses the asynchronous computation represented by the future. If the computation is already paused, this function does nothing. AnyQFutureWatcher 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.

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

See alsoisPaused(),pause(),resume(), andtogglePaused().

void QFuture::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()).

See alsosetPaused(),pause(), andresume().

void QFuture::waitForFinished()

Waits for the asynchronous computation to finish (includingcancel()ed computations).

QFuture::operator T() const

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 callingresult() or resultAt(0).

See alsoresult(),resultAt(), andresults().

bool QFuture::operator!=(constQFuture & other) const

Returns true ifother isnot a copy of this future; otherwise returns false.

QFuture & QFuture::operator=(constQFuture & other)

Assignsother to this future and returns a reference to this future.

bool QFuture::operator==(constQFuture & other) const

Returns true ifother is a copy of this future; otherwise returns false.

You may use the documentation under the terms of theGNU Free Documentation License version 1.3, as published by the Free Software Foundation. Alternatively, you may use the documentation in accordance with the terms contained in a written agreement between you and Digia.
Notes provided by the Qt Community

Write a comment

Sorry, you must belogged in to post a comment.

No notes

Creative Commons Attribution-ShareAlike 2.5 Generic

Community Notes are available under

Attribution-Share Alike 2.5 Generic

 

© 2013 Qt Project Hosting. Qt® and the Qt logo is a registered trade mark of Digia plc and/or its subsidiaries and is used pursuant to a license from Digia plc and/or its subsidiaries.
All other trademarks are property of their respective owners.Privacy Policy
This site is hosted byGitorious AS. Your use of this web site is governed bythese terms of service.

Qt Project Hosting, P.O. Box 4332 Nydalen, 0402 Oslo, Norway. Org. Nr. 997 447 913

You are about to flag this item as unappropriate.


[8]ページ先頭

©2009-2025 Movatter.jp