Qt 4.8
Classes | Functions
qdbusreply.h File Reference
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
#include <QtDBus/qdbusmacros.h>
#include <QtDBus/qdbusmessage.h>
#include <QtDBus/qdbuserror.h>
#include <QtDBus/qdbusextratypes.h>
#include <QtDBus/qdbuspendingreply.h>

Go to the source code of this file.

Classes

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

Functions

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

Function Documentation

◆ qDBusReplyFill()

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.

Warning
This function is not part of the public interface.

Definition at line 229 of file qdbusreply.cpp.

Referenced by QDBusReply< QStringList >::operator=().

230 {
231  error = reply;
232 
233  if (error.isValid()) {
234  data = QVariant(); // clear it
235  return;
236  }
237 
238  if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
239  data = reply.arguments().at(0);
240  return;
241  }
242 
243  const char *expectedSignature = QDBusMetaType::typeToSignature(data.userType());
244  const char *receivedType = 0;
245  QByteArray receivedSignature;
246 
247  if (reply.arguments().count() >= 1) {
248  if (reply.arguments().at(0).userType() == QDBusMetaTypeId::argument) {
249  // compare signatures instead
251  receivedSignature = arg.currentSignature().toLatin1();
252  if (receivedSignature == expectedSignature) {
253  // matched. Demarshall it
254  QDBusMetaType::demarshall(arg, data.userType(), data.data());
255  return;
256  }
257  } else {
258  // not an argument and doesn't match?
259  int type = reply.arguments().at(0).userType();
260  receivedType = QVariant::typeToName(QVariant::Type(type));
261  receivedSignature = QDBusMetaType::typeToSignature(type);
262  }
263  }
264 
265  // error
266  if (receivedSignature.isEmpty())
267  receivedSignature = "no signature";
268  QString errorMsg;
269  if (receivedType) {
270  errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\" (%4), "
271  "expected \"%2\" (%3)")
272  .arg(QLatin1String(receivedSignature),
273  QLatin1String(expectedSignature),
274  QLatin1String(data.typeName()),
275  QLatin1String(receivedType));
276  } else {
277  errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\", "
278  "expected \"%2\" (%3)")
279  .arg(QLatin1String(receivedSignature),
280  QLatin1String(expectedSignature),
281  QLatin1String(data.typeName()));
282  }
283 
284  error = QDBusError(QDBusError::InvalidSignature, errorMsg);
285  data = QVariant(); // clear it
286 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
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
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QString currentSignature() const
Returns the type signature of the D-Bus type this QDBusArgument object is currently pointing to...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
void * data()
Definition: qvariant.cpp:3077
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
static bool demarshall(const QDBusArgument &, int id, void *data)
Executes the demarshalling of type id (whose data will be placed in data) from the D-Bus marshalling ...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static int argument
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571