Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QFutureWatcher Class Reference
[QtCore module]

The QFutureWatcher class allows monitoring a QFuture using signals and slots. More...

 #include <QFutureWatcher>

Inherits QObject.

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.4.

Public Functions

  • 29 public functions inherited from QObject

Public Slots

  • 1 public slot inherited from QObject

Signals

Additional Inherited Members

  • 1 property inherited from QObject
  • 5 static public members inherited from QObject
  • 7 protected functions inherited from QObject

Detailed Description

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:

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


Member Function Documentation

QFutureWatcher::QFutureWatcher ( QObject * parent = 0 )

Constructs a new QFutureWatcher with the given parent.

QFutureWatcher::~QFutureWatcher ()

Destroys the QFutureWatcher.

void QFutureWatcher::cancel ()   [slot]

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

Currently available results may still be accessed on a canceled QFuture, but new results will not become available after calling this function. Also, this QFutureWatcher will not deliver progress and result ready signals once canceled. This includes the progressValueChanged(), progressRangeChanged(), progressTextChanged(), resultReadyAt(), and resultsReadyAt() signals.

Be aware that not all asynchronous computations can be canceled. For example, the QFuture returned by QtConcurrent::run() cannot be canceled; but the QFuture returned by QtConcurrent::mappedReduced() can.

void QFutureWatcher::canceled ()   [signal]

This signal is emitted if the watched future is canceled.

void QFutureWatcher::finished ()   [signal]

This signal is emitted when the watched future finishes.

QFuture<T> QFutureWatcher::future () const

Returns the watched future.

See also setFuture().

bool QFutureWatcher::isCanceled () const

Returns 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. See cancel() for more details.

bool QFutureWatcher::isFinished () const

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

bool QFutureWatcher::isPaused () const

Returns 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. See setPaused() for more details.

See also setPaused() and togglePaused().

bool QFutureWatcher::isRunning () const

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

bool QFutureWatcher::isStarted () const

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

void QFutureWatcher::pause ()   [slot]

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

See also resume().

void QFutureWatcher::paused ()   [signal]

This signal is emitted when the watched future is paused.

See also setPaused().

int QFutureWatcher::progressMaximum () const

Returns the maximum progressValue().

See also progressValue() and progressMinimum().

int QFutureWatcher::progressMinimum () const

Returns the minimum progressValue().

See also progressValue() and progressMaximum().

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

The progress range for the watched future has changed to minimum and maximum

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.

void QFutureWatcher::progressTextChanged ( const QString & progressText )   [signal]

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 the progressMinimum() and progressMaximum().

See also progressMinimum() and progressMaximum().

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

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 (where progressValue equals the maximum value) will always be delivered.

T QFutureWatcher::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 also resultAt().

T QFutureWatcher::resultAt ( int index ) const

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

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

This signal is emitted when the watched future reports a ready result at index. 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, call future().result(index);

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

This signal is emitted when the watched future reports ready results. The results are indexed from beginIndex to endIndex.

void QFutureWatcher::resume ()   [slot]

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

See also pause().

void QFutureWatcher::resumed ()   [signal]

This signal is emitted when the watched future is resumed.

void QFutureWatcher::setFuture ( const QFuture<T> & future )

Starts watching the given future.

See also future().

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

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

See also paused(), pause(), resume(), and togglePaused().

void QFutureWatcher::setPendingResultsLimit ( int limit )

The setPendingResultsLimit() provides throttling control. 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.

void QFutureWatcher::started ()   [signal]

This signal is emitted when this QFutureWatcher starts watching the future set with setFuture().

void QFutureWatcher::togglePaused ()   [slot]

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 calling setPaused(!isPaused()).

See also setPaused(), pause(), and resume().

void QFutureWatcher::waitForFinished ()

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 41
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Génération de contenu dans des threads

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.5
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web