1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page qtdbus-overview.html
6 \title Qt D-Bus Overview
7 \brief Provides insight into the Qt Qt D-Bus module.
9 D-Bus is an Inter-Process Communication (IPC) and Remote Procedure
10 Calling (RPC) mechanism originally developed for Linux to replace
11 existing and competing IPC solutions with one unified protocol. It
12 was also designed to allow communication between system-level
13 processes (such as printer and hardware driver services) and
14 normal user processes.
16 It uses a fast, binary message-passing protocol, which is suitable
17 for same-machine communication due to its low latency and low
18 overhead. Its specification is currently defined by the
19 \tt{freedesktop.org} project and is available to all parties.
21 Communication, in general, happens through a central server
22 application called the "bus" (hence the name), but direct
23 application-to-application communication is also possible. When
24 communicating on a bus, applications can query which other
25 applications and services are available, as well as activate one
30 D-Bus buses are used when many-to-many communication is
31 desired. In order to achieve that, a central server is launched
32 before any application can connect to the bus. This server is
33 responsible for keeping track of the applications that are
34 connected and for properly routing messages from their source to
37 In addition, D-Bus defines two well-known buses, called the
38 system bus and the session bus. These buses are special in the
39 sense that they have well-defined semantics: some services are
40 defined to be found in one or both of these buses.
42 For example, an application wishing to query the list of hardware
43 devices attached to the computer will probably communicate to a
44 service available on the system bus, while the service providing
45 opening of the user's web browser will probably be found on the
48 On the system bus, you can also expect to find restrictions on
49 what services each application is allowed to offer. Therefore, you
50 can be reasonably certain that if a certain service is present,
51 it's being offered by a trusted application.
57 On the low level, applications communicate over D-Bus by sending
58 messages to one another. Messages are used to relay the remote
59 procedure calls as well as the replies and errors associated
60 with them. When used over a bus, messages have a destination,
61 which means they are routed only to the interested parties,
62 avoiding congestion due to "swarming" or broadcasting.
64 A special kind of message called a "signal message"
65 (a concept based on Qt's \l {Signals and Slots} mechanism),
66 however, does not have a pre-defined destination. Since its
67 purpose is to be used in a one-to-many context, signal messages
68 are designed to work over an "opt-in" mechanism.
70 The Qt D-Bus module fully encapsulates the low-level concept of
71 messages into a simpler, object-oriented approach familiar to Qt
72 developers. In most cases, the developer need not worry about
73 sending or receiving messages.
75 \section2 Service Names
77 When communicating over a bus, applications obtain what is
78 called a "service name": it is how that application chooses to be
79 known by other applications on the same bus. The service names
80 are brokered by the D-Bus bus daemon and are used to
81 route messages from one application to another. An analogous
82 concept to service names are IP addresses and hostnames: a
83 computer normally has one IP address and may have one or more
84 hostnames associated with it, according to the services that it
85 provides to the network.
87 On the other hand, if a bus is not used, service names are also
88 not used. If we compare this to a computer network again, this
89 would equate to a point-to-point network: since the peer is
90 known, there is no need to use hostnames to find it or its IP
93 The format of a D-Bus service name is in fact very similar to a
94 host name: it is a dot-separated sequence of letters and
95 digits. The common practice is even to name your service name
96 according to the domain name of the organization that defined
99 For example, the D-Bus service is defined by
100 \tt{freedesktop.org} and can be found on the bus under the
103 \snippet code/doc_src_introtodbus.qdoc 0
105 \section2 Object Paths
107 Like network hosts, applications provide specific services to
108 other applications by exporting objects. Those objects are
109 hierarchically organized, much like the parent-child
110 relationship that classes derived from QObject possess. One
111 difference, however, is that there is the concept of "root
112 object", which all objects have as the ultimate parent.
114 If we continue our analogy with Web services, object paths
115 equate to the path part of a URL:
117 \image qurl-ftppath.png
119 Like them, object paths in D-Bus are formed resembling path
120 names on the filesystem: they are slash-separated labels, each
121 consisting of letters, digits and the underscore character
122 ("\_"). They must always start with a slash and must not end with
127 Interfaces are similar to C++ abstract classes and Java's
128 \c interface keyword and declare the "contract" that is
129 established between caller and callee. That is, they establish
130 the names of the methods, signals, and properties that are
131 available as well as the behavior that is expected from either
132 side when communication is established.
134 Qt uses a very similar mechanism in its \l {How to Create Qt
135 Plugins}{Plugin system}: Base classes in C++ are associated
136 with a unique identifier by way of the Q_DECLARE_INTERFACE()
139 D-Bus interface names are, in fact, named in a manner similar to
140 what is suggested by the Qt Plugin System: an identifier usually
141 constructed from the domain name of the entity that defined that
144 \section2 Cheat Sheet
146 To facilitate remembering of the naming formats and their
147 purposes, the following table can be used:
150 \header \li D-Bus Concept \li Analogy \li Name format
151 \row \li Service name \li Network hostnames \li Dot-separated
152 ("looks like a hostname")
153 \row \li Object path \li URL path component \li Slash-separated
154 ("looks like a path")
155 \row \li Interface \li Plugin identifier \li Dot-separated
160 When developing applications that use D-Bus, it is sometimes useful to be able
161 to see information about the messages that are sent and received across the
162 bus by each application.
164 This feature can be enabled on a per-application basis by setting the
165 \c QDBUS_DEBUG environment variable before running each application.
166 For example, we can enable debugging only for the car in the
167 \l{D-Bus Remote Controlled Car} example by running the controller and the
168 car in the following way:
170 \snippet code/doc_src_introtodbus.qdoc QDBUS_DEBUG
172 Information about the messages will be written to the console the application