Logo Search packages:      
Sourcecode: kdbus version File versions  Download package

QDBusMessage Class Reference

#include <qdbusmessage.h>

List of all members.

Detailed Description

A message converts and transports data over DBus.

A QDBusMessage is implicitly shared, similar to a QString, i.e. copying a message creates just a shallow copy.

The QDBusMessage is the Qt3 bindings means of encapsulating data for a method call, a method reply or an error.

Data specifying the sender and receipient is directly accessible through getter methods, while data, e.g. method parameters or return values, are managed as a list of QVariant.

To create a message suitable for sending use one of the static factory methods:

for applications that just want to perform method calls and/or receive signals, it is usually more convenient to use QDBusProxy instead.
Message sending is achieved through QDBusConnection


   QDBusConnection con = QDBusConnection::addConnection(QDBusConnection::SessionBus);

   // receipient service is the bus' main interface

   QString service   = "org.freedesktop.DBus";
   QString path      = "/org/freedesktop/DBus";
   QString interface = "org.freedesktop.DBus";

   QDBusMessage msg = QBusMessage::methodCall(service, path, interface, "ListNames");

   QDBusMessage reply = con.sendWithReply(msg);

   // awaiting for a message list

   if (reply.type() != QDBusMessage::ReplyMessage || reply.count() != 2 ||
       reply[0].type() != QVariant::StringList)
       // error handling here
       QStringList list = reply[0].toStringList();

       // reply handling here

A service returning such a reply would do something like this

   bool Service::handleMethodCall(const QDBusMessage& call)
       // leaving out checks for correctness

       QStringList result;
       result << "Foo" << "Bar";

       QDBusMessage reply = QDBusMessage::methodReply(call);
       reply << QVariant(result);


       return true;

Definition at line 113 of file qdbusmessage.h.

Public Types

enum  { DefaultTimeout = -1, NoTimeout = INT_MAX }
 Anonymous enum for timeout constants. More...
enum  MessageType {
  InvalidMessage, MethodCallMessage, ReplyMessage, ErrorMessage,
 DBus message types. More...

Public Member Functions

QDBusError error () const
 Returns the error of an error message.
QString interface () const
 Returns the message's interface name.
QString member () const
 Returns the message's member name.
QDBusMessageoperator= (const QDBusMessage &other)
 Creates a shallow copy of the given message.
QString path () const
 Returns the message's object path.
 QDBusMessage (const QDBusMessage &other)
 Creates a shallow copy of the given message.
 QDBusMessage ()
 Creates an empty and invalid message.
int replySerialNumber () const
 Returns the message's reply serial number.
QString sender () const
 Returns the name of the message sender.
int serialNumber () const
 Returns the message's serial number.
void setTimeout (int ms)
 Sets the message's timeout.
int timeout () const
 Returns the message's timeout.
DBusMessage * toDBusMessage () const
 Creates a raw DBus message from this Qt3-bindings message.
MessageType type () const
 Returns which kind of message this is.
 ~QDBusMessage ()
 Destroys a message.

Static Public Member Functions

static QDBusMessage fromDBusMessage (DBusMessage *dmsg)
 Creates a Qt3-bindings message from the given raw DBus message.
static QDBusMessage methodCall (const QString &service, const QString &path, const QString &interface, const QString &method)
 Creates a message for sending a DBus method call.
static QDBusMessage methodError (const QDBusMessage &other, const QDBusError &error)
 Creates a message for replying to a DBus method call.
static QDBusMessage methodReply (const QDBusMessage &other)
 Creates a message for replying to a DBus method call.
static QDBusMessage signal (const QString &path, const QString &interface, const QString &member)
 Creates a message for sending a DBus signal.

Private Attributes

QDBusMessagePrivate * d


class QDBusConnection

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

Generated by  Doxygen 1.6.0   Back to index