Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QFutureWatcher Class

TheQFutureWatcher class allows monitoring aQFuture using signals and slots.More...

Header:#include <QFutureWatcher>
Since: Qt 4.4
Inherits:QObject

Note: All functions in this class arereentrant.

Public Functions

QFutureWatcher(QObject * parent = 0)
~QFutureWatcher()
QFuture<T>future() const
boolisCanceled() const
boolisFinished() const
boolisPaused() const
boolisRunning() const
boolisStarted() const
intprogressMaximum() const
intprogressMinimum() const
QStringprogressText() const
intprogressValue() const
Tresult() const
TresultAt(int index) const
voidsetFuture(const QFuture<T> & future)
voidsetPendingResultsLimit(int limit)
voidwaitForFinished()
  • 29 public functions inherited fromQObject

Public Slots

voidcancel()
voidpause()
voidresume()
voidsetPaused(bool paused)
voidtogglePaused()
  • 1 public slot inherited fromQObject

Signals

voidcanceled()
voidfinished()
voidpaused()
voidprogressRangeChanged(int minimum, int maximum)
voidprogressTextChanged(const QString & progressText)
voidprogressValueChanged(int progressValue)
voidresultReadyAt(int index)
voidresultsReadyAt(int beginIndex, int endIndex)
voidresumed()
voidstarted()

Additional Inherited Members

  • 1 property inherited fromQObject
  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQFutureWatcher class allows monitoring aQFuture using signals and slots.

QFutureWatcher provides information and notifications about aQFuture. Use thesetFuture() function to start watching a particularQFuture. Thefuture() function returns the future set withsetFuture().

For convenience, several ofQFuture's functions are also available inQFutureWatcher:progressValue(),progressMinimum(),progressMaximum(),progressText(),isStarted(),isFinished(),isRunning(),isCanceled(),isPaused(),waitForFinished(),result(), andresultAt(). Thecancel(),setPaused(),pause(),resume(), andtogglePaused() functions are slots inQFutureWatcher.

Status changes are reported via thestarted(),finished(),canceled(),paused(),resumed(),resultReadyAt(), andresultsReadyAt() signals. Progress information is provided from theprogressRangeChanged(), voidprogressValueChanged(), andprogressTextChanged() signals.

Throttling control is provided by thesetPendingResultsLimit() function. When the number of pendingresultReadyAt() orresultsReadyAt() 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:

// 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 byQtConcurrent::run() cannot be canceled; but the future returned byQtConcurrent::mappedReduced() can.

QFutureWatcher<void> is specialized to not contain any of the result fetching functions. AnyQFuture<T> can be watched by aQFutureWatcher<void> as well. This is useful if only status or progress information is needed; not the actual result data.

See alsoQFuture andQt Concurrent.

Member Function Documentation

QFutureWatcher::QFutureWatcher(QObject * parent = 0)

Constructs a newQFutureWatcher with the givenparent.

QFutureWatcher::~QFutureWatcher()

Destroys theQFutureWatcher.

[slot]void QFutureWatcher::cancel()

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

Currently available results may still be accessed on a canceledQFuture, but new results willnot become available after calling this function. Also, thisQFutureWatcher will not deliver progress and result ready signals once canceled. This includes theprogressValueChanged(),progressRangeChanged(),progressTextChanged(),resultReadyAt(), andresultsReadyAt() signals.

Be aware that not all asynchronous computations can be canceled. For example, theQFuture returned byQtConcurrent::run() cannot be canceled; but theQFuture returned byQtConcurrent::mappedReduced() can.

[signal]void QFutureWatcher::canceled()

This signal is emitted if the watched future is canceled.

[signal]void QFutureWatcher::finished()

This signal is emitted when the watched future finishes.

QFuture<T> QFutureWatcher::future() const

Returns the watched future.

See alsosetFuture().

bool QFutureWatcher::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 QFutureWatcher::isFinished() const

Returns true if the asynchronous computation represented by thefuture() has finished; otherwise returns false.

bool QFutureWatcher::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 QFutureWatcher::isRunning() const

Returns true if the asynchronous computation represented by thefuture() is currently running; otherwise returns false.

bool QFutureWatcher::isStarted() const

Returns true if the asynchronous computation represented by thefuture() has been started; otherwise returns false.

[slot]void QFutureWatcher::pause()

Pauses the asynchronous computation represented by thefuture(). This is a convenience method that simply callssetPaused(true).

See alsoresume().

[signal]void QFutureWatcher::paused()

This signal is emitted when the watched future is paused.

See alsosetPaused().

int QFutureWatcher::progressMaximum() const

Returns the maximumprogressValue().

See alsoprogressValue() andprogressMinimum().

int QFutureWatcher::progressMinimum() const

Returns the minimumprogressValue().

See alsoprogressValue() andprogressMaximum().

[signal]void QFutureWatcher::progressRangeChanged(int minimum,int maximum)

The progress range for the watched future has changed tominimum andmaximum

QString QFutureWatcher::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.

[signal]void QFutureWatcher::progressTextChanged(constQString & progressText)

This signal is emitted when the watched future reports textual progress information,progressText.

int QFutureWatcher::progressValue() const

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

See alsoprogressMinimum() andprogressMaximum().

[signal]void QFutureWatcher::progressValueChanged(int progressValue)

This signal is emitted when the watched future reports progress,progressValue gives the current progress. In order to avoid overloading the GUI event loop,QFutureWatcher limits the progress signal emission rate. This means that listeners connected to this slot might not get all progress reports the future makes. The last progress update (whereprogressValue equals the maximum value) will always be delivered.

T QFutureWatcher::result() const

Returns the first result in thefuture(). 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 callingresultAt(0).

See alsoresultAt().

T QFutureWatcher::resultAt(int index) const

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

See alsoresult().

[signal]void QFutureWatcher::resultReadyAt(int index)

This signal is emitted when the watched future reports a ready result atindex. If the future reports multiple results, the index will indicate which one it is. Results can be reported out-of-order. To get the result, callfuture().result(index);

[signal]void QFutureWatcher::resultsReadyAt(int beginIndex,int endIndex)

This signal is emitted when the watched future reports ready results. The results are indexed frombeginIndex toendIndex.

[slot]void QFutureWatcher::resume()

Resumes the asynchronous computation represented by thefuture(). This is a convenience method that simply callssetPaused(false).

See alsopause().

[signal]void QFutureWatcher::resumed()

This signal is emitted when the watched future is resumed.

void QFutureWatcher::setFuture(constQFuture<T> & future)

Starts watching the givenfuture.

One of the signals might be emitted for the current state of thefuture. For example, if the future is already stopped, the finished signal will be emitted.

To avoid a race condition, it is important to call this functionafter doing the connections.

See alsofuture().

[slot]void QFutureWatcher::setPaused(bool paused)

Ifpaused is true, this function pauses the asynchronous computation represented by thefuture(). If the computation is already paused, this function does nothing. ThisQFutureWatcher will stop delivering progress and result ready signals while the future is paused. Signal delivery will continue once the computation 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, theQFuture returned byQtConcurrent::run() cannot be paused; but theQFuture returned byQtConcurrent::mappedReduced() can.

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

void QFutureWatcher::setPendingResultsLimit(int limit)

The setPendingResultsLimit() provides throttling control. When the number of pendingresultReadyAt() orresultsReadyAt() signals exceeds thelimit, the computation represented by the future will be throttled automatically. The computation will resume once the number of pending signals drops below thelimit.

[signal]void QFutureWatcher::started()

This signal is emitted when thisQFutureWatcher starts watching the future set withsetFuture().

[slot]void QFutureWatcher::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 becomes paused. This is a convenience method for callingsetPaused(!isPaused()).

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

void QFutureWatcher::waitForFinished()

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

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp