QDBusConnection Class

The QDBusConnection class represents a connection to the D-Bus bus daemon. More...

Header: #include <QDBusConnection>
qmake: QT += dbus
Since: Qt 4.2

This class was introduced in Qt 4.2.

Public Types

enum BusType { SessionBus, SystemBus, ActivationBus }
enum ConnectionCapability { UnixFileDescriptorPassing }
enum RegisterOption { ExportAdaptors, ExportScriptableSlots, ExportScriptableSignals, ExportScriptableProperties, ExportScriptableInvokables, …, ExportChildObjects }
enum UnregisterMode { UnregisterNode, UnregisterTree }

Detailed Description

This class is the initial point in a D-Bus session. Using it, you can get access to remote objects, interfaces; connect remote signals to your object's slots; register objects, etc.

D-Bus connections are created using the connectToBus() function, which opens a connection to the server daemon and does the initial handshaking, associating that connection with a name. Further attempts to connect using the same name will return the same connection.

The connection is then torn down using the disconnectFromBus() function.

Once disconnected, calling connectToBus() will not reestablish a connection, you must create a new QDBusConnection instance.

As a convenience for the two most common connection types, the sessionBus() and systemBus() functions return open connections to the session server daemon and the system server daemon, respectively. Those connections are opened when first used and are closed when the QCoreApplication destructor is run.

D-Bus also supports peer-to-peer connections, without the need for a bus server daemon. Using this facility, two applications can talk to each other and exchange messages. This can be achieved by passing an address to connectToBus() function, which was opened by another D-Bus application using QDBusServer.

Member Type Documentation

enum QDBusConnection::BusType

Specifies the type of the bus connection. The valid bus types are:

ConstantValueDescription
QDBusConnection::SessionBus0the session bus, associated with the running desktop session
QDBusConnection::SystemBus1the system bus, used to communicate with system-wide processes
QDBusConnection::ActivationBus2the activation bus, the "alias" for the bus that started the service

On the Session Bus, one can find other applications by the same user that are sharing the same desktop session (hence the name). On the System Bus, however, processes shared for the whole system are usually found.

enum QDBusConnection::ConnectionCapability

This enum describes the available capabilities for a D-Bus connection.

ConstantValueDescription
QDBusConnection::UnixFileDescriptorPassing0x0001enables passing of Unix file descriptors to other processes (see QDBusUnixFileDescriptor)

This enum was introduced or modified in Qt 4.8.

See also connectionCapabilities().

enum QDBusConnection::RegisterOption

Specifies the options for registering objects with the connection. The possible values are:

ConstantValueDescription
QDBusConnection::ExportAdaptors0x01export the contents of adaptors found in this object
QDBusConnection::ExportScriptableSlots0x10export this object's scriptable slots
QDBusConnection::ExportScriptableSignals0x20export this object's scriptable signals
QDBusConnection::ExportScriptableProperties0x40export this object's scriptable properties
QDBusConnection::ExportScriptableInvokables0x80export this object's scriptable invokables
QDBusConnection::ExportScriptableContents0xf0shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties
QDBusConnection::ExportNonScriptableSlots0x100export this object's non-scriptable slots
QDBusConnection::ExportNonScriptableSignals0x200export this object's non-scriptable signals
QDBusConnection::ExportNonScriptableProperties0x400export this object's non-scriptable properties
QDBusConnection::ExportNonScriptableInvokables0x800export this object's non-scriptable invokables
QDBusConnection::ExportNonScriptableContents0xf00shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties
QDBusConnection::ExportAllSlotsExportScriptableSlots|ExportNonScriptableSlotsexport all of this object's slots
QDBusConnection::ExportAllSignalsExportScriptableSignals|ExportNonScriptableSignalsexport all of this object's signals
QDBusConnection::ExportAllPropertiesExportScriptableProperties|ExportNonScriptablePropertiesexport all of this object's properties
QDBusConnection::ExportAllInvokablesExportScriptableInvokables|ExportNonScriptableInvokablesexport all of this object's invokables
QDBusConnection::ExportAllContentsExportScriptableContents|ExportNonScriptableContentsexport all of this object's contents
QDBusConnection::ExportChildObjects0x1000export this object's child objects

See also registerObject(), QDBusAbstractAdaptor, and Using adaptors.

enum QDBusConnection::UnregisterMode

The mode for unregistering an object path:

ConstantValueDescription
QDBusConnection::UnregisterNode0unregister this node only: do not unregister child objects
QDBusConnection::UnregisterTree1unregister this node and all its sub-tree

Note, however, if this object was registered with the ExportChildObjects option, UnregisterNode will unregister the child objects too.