Qt 4.8
Public Functions | Private Types | Properties | List of all members
QDBusReply< T > Class Template Reference

The QDBusReply class stores the reply for a method call to a remote object. More...

#include <qdbusreply.h>

Public Functions

const QDBusErrorerror ()
 Returns the error code that was returned from the remote function call. More...
 
bool isValid () const
 Returns true if no error occurred; otherwise, returns false. More...
 
 operator Type () const
 Returns the same as value(). More...
 
QDBusReplyoperator= (const QDBusMessage &reply)
 Makes this object contain the reply specified by message message. More...
 
QDBusReplyoperator= (const QDBusPendingCall &pcall)
 Makes this object contain the reply specified by the pending asynchronous call pcall. More...
 
QDBusReplyoperator= (const QDBusError &dbusError)
 Sets this object to contain the error code given by error. More...
 
QDBusReplyoperator= (const QDBusReply &other)
 Makes this object be a copy of the object other. More...
 
 QDBusReply (const QDBusMessage &reply)
 Automatically construct a QDBusReply object from the reply message reply, extracting the first return value from it if it is a success reply. More...
 
 QDBusReply (const QDBusPendingCall &pcall)
 Automatically construct a QDBusReply object from the asynchronous pending call pcall. More...
 
 QDBusReply (const QDBusPendingReply< T > &reply)
 Constructs a QDBusReply object from the pending reply message, reply. More...
 
 QDBusReply (const QDBusError &dbusError=QDBusError())
 Constructs an error reply from the D-Bus error code given by error. More...
 
Type value () const
 Returns the remote function's calls return value. More...
 

Private Types

typedef T Type
 

Properties

Type m_data
 
QDBusError m_error
 

Detailed Description

template<typename T>
class QDBusReply< T >

The QDBusReply class stores the reply for a method call to a remote object.

Attention
Module: QtDBus
Since
4.2

A QDBusReply object is a subset of the QDBusMessage object that represents a method call's reply. It contains only the first output argument or the error code and is used by QDBusInterface-derived classes to allow returning the error code as the function's return argument.

It can be used in the following manner:

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

If the remote method call cannot fail, you can skip the error checking:

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

However, if it does fail under those conditions, the value returned by QDBusReply::value() is a default-constructed value. It may be indistinguishable from a valid return value.

QDBusReply objects are used for remote calls that have no output arguments or return values (i.e., they have a "void" return type). Use the isValid() function to test if the reply succeeded.

See also
QDBusMessage, QDBusInterface

Definition at line 65 of file qdbusreply.h.

Typedefs

◆ Type

template<typename T>
typedef T QDBusReply< T >::Type
private

Definition at line 67 of file qdbusreply.h.

Constructors and Destructors

◆ QDBusReply() [1/4]

template<typename T>
QDBusReply< T >::QDBusReply ( const QDBusMessage reply)
inline

Automatically construct a QDBusReply object from the reply message reply, extracting the first return value from it if it is a success reply.

Definition at line 69 of file qdbusreply.h.

70  {
71  *this = reply;
72  }

◆ QDBusReply() [2/4]

template<typename T>
QDBusReply< T >::QDBusReply ( const QDBusPendingCall pcall)
inline

Automatically construct a QDBusReply object from the asynchronous pending call pcall.

If the call isn't finished yet, QDBusReply will call QDBusPendingCall::waitForFinished(), which is a blocking operation.

If the return types patch, QDBusReply will extract the first return argument from the reply.

Definition at line 81 of file qdbusreply.h.

82  {
83  *this = pcall;
84  }

◆ QDBusReply() [3/4]

template<typename T>
QDBusReply< T >::QDBusReply ( const QDBusPendingReply< T > &  reply)
inline

Constructs a QDBusReply object from the pending reply message, reply.

Definition at line 91 of file qdbusreply.h.

92  {
93  *this = static_cast<QDBusPendingCall>(reply);
94  }
The QDBusPendingCall class refers to one pending asynchronous call.

◆ QDBusReply() [4/4]

template<typename T>
QDBusReply< T >::QDBusReply ( const QDBusError dbusError = QDBusError())
inline

Constructs an error reply from the D-Bus error code given by error.

Definition at line 96 of file qdbusreply.h.

97  : m_error(dbusError), m_data(Type())
98  {
99  }
Type m_data
Definition: qdbusreply.h:130
QDBusError m_error
Definition: qdbusreply.h:129

Functions

◆ error()

template<typename T>
QDBusReply< T >::error ( )
inline

Returns the error code that was returned from the remote function call.

If the remote call did not return an error (i.e., if it succeeded), then the QDBusError object that is returned will not be a valid error code (QDBusError::isValid() will return false).

See also
isValid()

Definition at line 116 of file qdbusreply.h.

Referenced by QConnmanManagerInterface::connectService(), QConnmanManagerInterface::disableTechnology(), QConnmanManagerInterface::enableTechnology(), QConnmanManagerInterface::lookupService(), QConnmanManagerInterface::registerCounter(), QConnmanManagerInterface::requestScan(), QOfonoSmsInterface::sendMessage(), and QConnmanManagerInterface::unregisterCounter().

116 { return m_error; }
QDBusError m_error
Definition: qdbusreply.h:129

◆ isValid()

template<typename T>
bool QDBusReply< T >::isValid ( ) const
inline

Returns true if no error occurred; otherwise, returns false.

See also
error()

Definition at line 114 of file qdbusreply.h.

Referenced by QConnmanManagerInterface::connectService(), QOfonoManagerInterface::getModems(), QOfonoNetworkRegistrationInterface::getOperators(), QOfonoDataConnectionManagerInterface::getPrimaryContexts(), QOfonoManagerInterface::getProperties(), QConnmanManagerInterface::getServices(), QConnmanManagerInterface::getTechnologies(), and QConnmanManagerInterface::lookupService().

114 { return !m_error.isValid(); }
bool isValid() const
Returns true if this is a valid error condition (i.e., if there was an error), otherwise false...
Definition: qdbuserror.cpp:356
QDBusError m_error
Definition: qdbusreply.h:129

◆ operator Type()

template<typename T>
QDBusReply< T >::operator Type ( ) const
inline

Returns the same as value().

This function is not available if the remote call returns void.

Definition at line 123 of file qdbusreply.h.

124  {
125  return m_data;
126  }
Type m_data
Definition: qdbusreply.h:130

◆ operator=() [1/4]

template<typename T>
QDBusReply< T >::operator= ( const QDBusMessage message)
inline

Makes this object contain the reply specified by message message.

If message is an error message, this function will copy the error code and message into this object

If message is a standard reply message and contains at least one parameter, it will be copied into this object, as long as it is of the correct type. If it's not of the same type as this QDBusError object, this function will instead set an error code indicating a type mismatch.

Definition at line 73 of file qdbusreply.h.

74  {
75  QVariant data(qMetaTypeId(&m_data), reinterpret_cast<void*>(0));
76  qDBusReplyFill(reply, m_error, data);
78  return *this;
79  }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int qMetaTypeId()
Definition: qmetatype.h:224
Q_DBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
Fills in the QDBusReply data error and data from the reply message reply.
Definition: qdbusreply.cpp:229
Type m_data
Definition: qdbusreply.h:130
static const char * data(const QByteArray &arr)
QDBusError m_error
Definition: qdbusreply.h:129
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ operator=() [2/4]

template<typename T>
QDBusReply< T >::operator= ( const QDBusPendingCall pcall)
inline

Makes this object contain the reply specified by the pending asynchronous call pcall.

If the call is not finished yet, this function will call QDBusPendingCall::waitForFinished() to block until the reply arrives.

If pcall finishes with an error message, this function will copy the error code and message into this object

If pcall finished with a standard reply message and contains at least one parameter, it will be copied into this object, as long as it is of the correct type. If it's not of the same type as this QDBusError object, this function will instead set an error code indicating a type mismatch.

Definition at line 85 of file qdbusreply.h.

86  {
87  QDBusPendingCall other(pcall);
88  other.waitForFinished();
89  return *this = other.reply();
90  }
The QDBusPendingCall class refers to one pending asynchronous call.

◆ operator=() [3/4]

template<typename T>
QDBusReply< T >::operator= ( const QDBusError error)
inline

Sets this object to contain the error code given by error.

You can later access it with error().

Definition at line 100 of file qdbusreply.h.

101  {
102  m_error = dbusError;
103  m_data = Type();
104  return *this;
105  }
Type m_data
Definition: qdbusreply.h:130
QDBusError m_error
Definition: qdbusreply.h:129

◆ operator=() [4/4]

template<typename T>
QDBusReply< T >::operator= ( const QDBusReply< T > &  other)
inline

Makes this object be a copy of the object other.

Definition at line 107 of file qdbusreply.h.

108  {
109  m_error = other.m_error;
110  m_data = other.m_data;
111  return *this;
112  }
Type m_data
Definition: qdbusreply.h:130
QDBusError m_error
Definition: qdbusreply.h:129

◆ value()

template<typename T>
QDBusReply< T >::value ( ) const
inline

Returns the remote function's calls return value.

If the remote call returned with an error, the return value of this function is undefined and may be undistinguishable from a valid return value.

This function is not available if the remote call returns void.

Definition at line 118 of file qdbusreply.h.

Referenced by QNetworkManagerInterfaceDeviceWireless::getAccessPoints(), QNetworkManagerInterface::getDevices(), QOfonoManagerInterface::getModems(), QOfonoNetworkRegistrationInterface::getOperators(), QOfonoDataConnectionManagerInterface::getPrimaryContexts(), QOfonoManagerInterface::getProperties(), QConnmanManagerInterface::getProperties(), QOfonoModemInterface::getProperties(), QConnmanProfileInterface::getProperties(), QOfonoNetworkRegistrationInterface::getProperties(), QConnmanServiceInterface::getProperties(), QOfonoNetworkOperatorInterface::getProperties(), QOfonoSimInterface::getProperties(), QConnmanTechnologyInterface::getProperties(), QOfonoDataConnectionManagerInterface::getProperties(), QOfonoPrimaryDataContextInterface::getProperties(), QOfonoSmsInterface::getProperties(), QConnmanManagerInterface::getServices(), QNetworkManagerSettingsConnection::getSettings(), QConnmanManagerInterface::getState(), QConnmanManagerInterface::getTechnologies(), QNetworkManagerSettings::listConnections(), qDBusReplyToScriptValue(), and QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection().

119  {
120  return m_data;
121  }
Type m_data
Definition: qdbusreply.h:130

Properties

◆ m_data

template<typename T>
Type QDBusReply< T >::m_data
private

◆ m_error

template<typename T>
QDBusError QDBusReply< T >::m_error
private

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