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  · 

QDBusPendingReply Class Reference
[QtDBus module]

The QDBusPendingReply class contains the reply to an asynchronous method call More...

 #include <QDBusPendingReply>

Inherits QDBusPendingCall.

This class was introduced in Qt 4.5.


Public Functions

QDBusPendingReply ()
QDBusPendingReply ( const QDBusPendingReply & other )
QDBusPendingReply ( const QDBusPendingCall & call )
QDBusPendingReply ( const QDBusMessage & message )
QVariant argumentAt ( int index ) const
Type argumentAt () const
int count () const
QDBusError error () const
bool isError () const
bool isFinished () const
bool isValid () const
QDBusMessage reply () const
T1 value () const
void waitForFinished ()
operator T1 () const
QDBusPendingReply & operator= ( const QDBusPendingReply & other )
QDBusPendingReply & operator= ( const QDBusPendingCall & call )
QDBusPendingReply & operator= ( const QDBusMessage & message )

Additional Inherited Members


Detailed Description

The QDBusPendingReply class contains the reply to an asynchronous method call

The QDBusPendingReply is a template class with up to 8 template parameters. Those parameters are the types that will be used to extract the contents of the reply's data.

This class is similar in functionality to QDBusReply, but with two important differences:

  • QDBusReply accepts exactly one return type, whereas QDBusPendingReply can have from 1 to 8 types
  • QDBusReply only works on already completed replies, whereas QDBusPendingReply allows one to wait for replies from pending calls

Where with QDBusReply you would write:

 QDBusReply<QString> reply = interface->call("RemoteMethod");
 if (reply.isValid())
     // use the returned value
     useValue(reply.value());
 else
     // call failed. Show an error condition.
     showError(reply.error());

with QDBusPendingReply, the equivalent code (including the blocking wait for the reply) would be:

     QDBusPendingReply<QString> reply = interface->asyncCall("RemoteMethod");
     reply.waitForFinished();
     if (reply.isError())
         // call failed. Show an error condition.
         showError(reply.error());
     else
         // use the returned value
         useValue(reply.value());

For method calls that have more than one output argument, with QDBusReply, you would write:

 QString reply = interface->call("RemoteMethod");

whereas with QDBusPendingReply, all of the output arguments should be template parameters:

     QDBusPendingReply<bool, QString> reply = interface->asyncCall("RemoteMethod");
     reply.waitForFinished();
     if (!reply.isError()) {
         if (reply.argumentAt<0>())
             showSuccess(reply.argumentAt<1>());
         else
             showFailure(reply.argumentAt<1>());
     }

QDBusPendingReply objects can be associated with QDBusPendingCallWatcher objects, which emit signals when the reply arrives.

See also QDBusPendingCallWatcher, QDBusReply, and QDBusAbstractInterface::asyncCall().


Member Function Documentation

QDBusPendingReply::QDBusPendingReply ()

Creates an empty QDBusPendingReply object. Without assigning a QDBusPendingCall object to this reply, QDBusPendingReply cannot do anything. All functions return their failure values.

QDBusPendingReply::QDBusPendingReply ( const QDBusPendingReply & other )

Creates a copy of the other QDBusPendingReply object. Just like QDBusPendingCall and QDBusPendingCallWatcher, this QDBusPendingReply object will share the same pending call reference. All copies share the same return values.

QDBusPendingReply::QDBusPendingReply ( const QDBusPendingCall & call )

Creates a QDBusPendingReply object that will take its contents from the call pending asynchronous call. This QDBusPendingReply object will share the same pending call reference as call.

QDBusPendingReply::QDBusPendingReply ( const QDBusMessage & message )

Creates a QDBusPendingReply object that will take its contents from the message message. In this case, this object will be already in its finished state and the reply's contents will be accessible.

See also isFinished().

QVariant QDBusPendingReply::argumentAt ( int index ) const

Returns the argument at position index in the reply's contents. If the reply doesn't have that many elements, this function's return value is undefined (will probably cause an assertion failure), so it is important to verify that the processing is finished and the reply is valid.

Type QDBusPendingReply::argumentAt () const

Returns the argument at position Index (which is a template parameter) cast to type Type. This function uses template code to determine the proper Type type, according to the type list used in the construction of this object.

Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed.

int QDBusPendingReply::count () const

Return the number of arguments the reply is supposed to have. This number matches the number of non-void template parameters in this class.

If the reply arrives with a different number of arguments (or with different types), it will be transformed into an error reply indicating a bad signature.

QDBusError QDBusPendingReply::error () const

Retrieves the error content of the reply message, if it has finished processing. If the reply message has not finished processing or if it contains a normal reply message (non-error), this function returns an invalid QDBusError.

bool QDBusPendingReply::isError () const

Returns true if the reply contains an error message, false if it contains a normal method reply.

If the pending call has not finished processing, this function also returns true.

bool QDBusPendingReply::isFinished () const

Returns true if the pending call has finished processing and the reply has been received. If this function returns true, the isError(), error() and reply() methods should return valid information.

Note that this function only changes state if you call waitForFinished() or if an external D-Bus event happens, which in general only happens if you return to the event loop execution.

See also QDBusPendingCallWatcher::isFinished().

bool QDBusPendingReply::isValid () const

Returns true if the reply contains a normal reply message, false if it contains anything else.

If the pending call has not finished processing, this function return false.

QDBusMessage QDBusPendingReply::reply () const

Retrieves the reply message received for the asynchronous call that was sent, if it has finished processing. If the pending call is not finished, this function returns a QDBusMessage of type QDBusMessage::InvalidMessage.

After it has finished processing, the message type will either be an error message or a normal method reply message.

T1 QDBusPendingReply::value () const

Returns the first argument in this reply, cast to type T1 (the first template parameter of this class). This is equivalent to calling argumentAt<0>().

This function is provided as a convenience, matching the QDBusReply::value() function.

Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed.

void QDBusPendingReply::waitForFinished ()

Suspends the execution of the calling thread until the reply is received and processed. After this function returns, isFinished() should return true, indicating the reply's contents are ready to be processed.

See also QDBusPendingCallWatcher::waitForFinished().

QDBusPendingReply::operator T1 () const

Returns the first argument in this reply, cast to type T1 (the first template parameter of this class). This is equivalent to calling argumentAt<0>().

This function is provided as a convenience, matching the QDBusReply::value() function.

Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed.

QDBusPendingReply & QDBusPendingReply::operator= ( const QDBusPendingReply & other )

Makes a copy of other and drops the reference to the current pending call. If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

QDBusPendingReply & QDBusPendingReply::operator= ( const QDBusPendingCall & call )

Makes this object take its contents from the call pending call and drops the reference to the current pending call. If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

QDBusPendingReply & QDBusPendingReply::operator= ( const QDBusMessage & message )

Makes this object take its contents from the message message and drops the reference to the current pending call. If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

After this function is finished, the QDBusPendingReply object will be in its "finished" state and the message contents will be accessible.

See also isFinished().

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 64
  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. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  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. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Quarterly au hasard

Logo

Réordonner les boutons

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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.6
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