Using D-Bus with Qt

D-Bus is a well known inter-process communication mechanism widely used in Linux environments. Qt offers some modules to work with D-Bus without the hassle of dealing with low level concepts. However, the docs are not as easy to grasp as you would expect. Here’s a quick and simple example to get acquainted with these concepts.

I won’t dig deep into the concepts of D-Bus, there are many tutorials out there about the topic. The bare minimum you need to know is this:

  • D-Bus offers a series of buses that processes can use to communicate with each other. The bus most commonly used with user apps is the session bus.
  • Applications usually connect to the session bus using a specific bus name, like com.josetomastocino.myapp.
  • Applications offer their functionality by exporting objects, which can be found at certain hierarchical paths, like /com/josetomastocino/myapp/InfoProvider.
  • Objects have methods and signals. Methods are called by the clients, can have arguments and may return values. Signals are broadcasted by the server applications and relayed to those clients listening for that signal on that particular bus.

How's this all implemented with Qt? Well, here's a diagram of the classes we'll be working with.

Image

Written on 2017-12-15