Qt 4.8
Classes | Public Types | Public Functions | Private Types | Private Functions | List of all members
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 > Class Template Reference

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

#include <qdbuspendingreply.h>

Inheritance diagram for QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >:
QDBusPendingCall

Classes

struct  Select
 

Public Types

enum  { Count = ForEach::Total }
 

Public Functions

QVariant argumentAt (int index) const
 Returns the argument at position index in the reply's contents. More...
 
template<int Index>
Type argumentAt () const
 Returns the argument at position Index (which is a template parameter) cast to type Type. More...
 
int count () const
 Return the number of arguments the reply is supposed to have. More...
 
QDBusError error () const
 Retrieves the error content of the reply message, if it has finished processing. More...
 
bool isError () const
 Returns true if the reply contains an error message, false if it contains a normal method reply. More...
 
bool isFinished () const
 Returns true if the pending call has finished processing and the reply has been received. More...
 
bool isValid () const
 Returns true if the reply contains a normal reply message, false if it contains anything else. More...
 
 operator T1 () const
 Returns the first argument in this reply, cast to type T1 (the first template parameter of this class). More...
 
QDBusPendingReplyoperator= (const QDBusPendingReply &other)
 Makes a copy of other and drops the reference to the current pending call. More...
 
QDBusPendingReplyoperator= (const QDBusPendingCall &call)
 Makes this object take its contents from the call pending call and drops the reference to the current pending call. More...
 
QDBusPendingReplyoperator= (const QDBusMessage &message)
 Makes this object take its contents from the message message and drops the reference to the current pending call. More...
 
 QDBusPendingReply ()
 Creates an empty QDBusPendingReply object. More...
 
 QDBusPendingReply (const QDBusPendingReply &other)
 Creates a copy of the other QDBusPendingReply object. More...
 
 QDBusPendingReply (const QDBusPendingCall &call)
 Creates a QDBusPendingReply object that will take its contents from the call pending asynchronous call. More...
 
 QDBusPendingReply (const QDBusMessage &message)
 Creates a QDBusPendingReply object that will take its contents from the message message. More...
 
QDBusMessage reply () const
 Retrieves the reply message received for the asynchronous call that was sent, if it has finished processing. More...
 
T1 value () const
 Returns the first argument in this reply, cast to type T1 (the first template parameter of this class). More...
 
void waitForFinished ()
 Suspends the execution of the calling thread until the reply is received and processed. More...
 
- Public Functions inherited from QDBusPendingCall
QDBusPendingCalloperator= (const QDBusPendingCall &other)
 Creates a copy of the other pending asynchronous call and drops the reference to the previously-referenced call. More...
 
 QDBusPendingCall (const QDBusPendingCall &other)
 Creates a copy of the other pending asynchronous call. More...
 
 ~QDBusPendingCall ()
 Destroys this copy of the QDBusPendingCall object. More...
 

Private Types

typedef QDBusPendingReplyTypes::ForEach< T1, T2, T3, T4, T5, T6, T7, T8 > ForEach
 

Private Functions

void assign (const QDBusPendingCall &call)
 
void assign (const QDBusMessage &message)
 
void calculateMetaTypes ()
 

Additional Inherited Members

- Static Public Functions inherited from QDBusPendingCall
static QDBusPendingCall fromCompletedCall (const QDBusMessage &message)
 Creates a QDBusPendingCall object based on the message msg. More...
 
static QDBusPendingCall fromError (const QDBusError &error)
 Creates a QDBusPendingCall object based on the error condition error. More...
 
- Protected Functions inherited from QDBusPendingCall
 QDBusPendingCall (QDBusPendingCallPrivate *dd)
 
- Protected Variables inherited from QDBusPendingCall
QExplicitlySharedDataPointer< QDBusPendingCallPrivated
 

Detailed Description

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
class QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >

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

Attention
Module: QtDBus
Since
4.5

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:

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, QDBusAbstractInterface::asyncCall()

Definition at line 115 of file qdbuspendingreply.h.

Typedefs

◆ ForEach

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
typedef QDBusPendingReplyTypes::ForEach<T1, T2, T3, T4, T5, T6, T7, T8> QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::ForEach
private

Definition at line 122 of file qdbuspendingreply.h.

Enumerations

◆ anonymous enum

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
anonymous enum

Constructors and Destructors

◆ QDBusPendingReply() [1/4]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::QDBusPendingReply ( )
inline

Creates an empty QDBusPendingReply object.

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

Definition at line 131 of file qdbuspendingreply.h.

132  { }

◆ QDBusPendingReply() [2/4]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::QDBusPendingReply ( const QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 > &  other)
inline

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.

Definition at line 133 of file qdbuspendingreply.h.

◆ QDBusPendingReply() [3/4]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::QDBusPendingReply ( const QDBusPendingCall call)
inline

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.

Definition at line 136 of file qdbuspendingreply.h.

137  { *this = call; }

◆ QDBusPendingReply() [4/4]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::QDBusPendingReply ( const QDBusMessage message)
inline

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

Definition at line 138 of file qdbuspendingreply.h.

139  { *this = message; }

Functions

◆ argumentAt() [1/2]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QVariant QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::argumentAt ( int  index) const
inline

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.

Definition at line 150 of file qdbuspendingreply.h.

quint16 index
QVariant argumentAt(int index) const

◆ argumentAt() [2/2]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
template<int Index>
Type QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::argumentAt ( ) const
inline

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.

◆ assign() [1/2]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
void QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::assign ( const QDBusPendingCall call)
inlineprivate

Definition at line 199 of file qdbuspendingreply.h.

200  {
203  }
void assign(const QDBusPendingCall &call)

◆ assign() [2/2]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
void QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::assign ( const QDBusMessage message)
inlineprivate

Definition at line 205 of file qdbuspendingreply.h.

206  {
209  }
void assign(const QDBusPendingCall &call)

◆ calculateMetaTypes()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
void QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::calculateMetaTypes ( )
inlineprivate

Definition at line 191 of file qdbuspendingreply.h.

192  {
193  if (!d) return;
194  int typeIds[Count > 0 ? Count : 1]; // use at least one since zero-sized arrays aren't valid
195  ForEach::fillMetaTypes(typeIds);
196  setMetaTypes(Count, typeIds);
197  }
QExplicitlySharedDataPointer< QDBusPendingCallPrivate > d

◆ count()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
int QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::count ( ) const
inline

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.

Definition at line 147 of file qdbuspendingreply.h.

◆ error()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusError QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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.

◆ isError()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
bool QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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.

Referenced by QNetworkManagerEngine::activationFinished().

◆ isFinished()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
bool QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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()

◆ isValid()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
bool QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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.

◆ operator T1()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::operator T1 ( ) const
inline

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.

◆ operator=() [1/3]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply & QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::operator= ( const QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 > &  other)
inline

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.

Definition at line 140 of file qdbuspendingreply.h.

141  { assign(other); return *this; }
void assign(const QDBusPendingCall &call)

◆ operator=() [2/3]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply & QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::operator= ( const QDBusPendingCall call)
inline

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.

Definition at line 142 of file qdbuspendingreply.h.

143  { assign(call); return *this; }
void assign(const QDBusPendingCall &call)

◆ operator=() [3/3]

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusPendingReply & QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::operator= ( const QDBusMessage message)
inline

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

Definition at line 144 of file qdbuspendingreply.h.

145  { assign(message); return *this; }
void assign(const QDBusPendingCall &call)

◆ reply()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
QDBusMessage QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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.

◆ value()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
T1 QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::value ( ) const
inline

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.

Referenced by QNetworkManagerEngine::activationFinished().

◆ waitForFinished()

template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
void QDBusPendingReply< T1, T2, T3, T4, T5, T6, T7, T8 >::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()

The documentation for this class was generated from the following files: