Some Lesser Known Qt Tools and Commands - Part 2
By Jeff Tranter | Wednesday, April 1, 2015
Continuing with our series of blog posts on some of the lesser known Qt commands, this time we will look at some tools related to Qt and D-Bus.
D-Bus (1) is an inter-process communication (IPC) system that allows multiple concurrently running computer programs to communicate.
It was developed by the freedesktop.org project to standardize services provided by Linux desktop environments. D-Bus is free software and runs on Linux and most POSIX-compatible operating systems, and a port to Windows exists. While originally developed for desktop systems, it is also commonly available and used on embedded Linux systems.
Qt (2) provides a set of interfaces to D-Bus, which are covered in detail in the Qt documentation. Some of the relevant Qt classes include QDBusConnection, QDBusInterface and QDBusMessage. Qt also comes with a handful of example applications that use D-Bus. Four D-Bus related tools are included in Qt: qdbus, qdbusviewer, qdbuscpp2xml and qdbusxml2cpp.
This is a command-line tool that can list D-Bus services, object paths, methods, signals and properties available. It has a number of options to control the output it produces, all of which are well covered in the Qt documentation.
Here is an example of the output on a Linux desktop system when running the command without any options, where the behavior is to list all of the services available on the bus. Not all of the output is shown, as it is quite long.
Command line options allow specifying the D-Bus service to connect to, path to the object or a D-Bus method to call.
This is a graphical tool to show D-Bus services, object paths, and the methods, signals and properties available. A typical screen shot is shown below. It is similar to the qtdbus tool, but offers a graphical user interface.
Qt provides some tools to make it easy to access D-Bus services from C++ code. One of the features of D-Bus is introspection. D-Bus objects that support this feature can be introspected at run time, returning an XML string that describes the object. The qdbuscpp2xml tool parses the C++ source or header file containing a QObject-derived class and produces the D-Bus Introspection XML.
The qdbusxml2cpp tool is also used for implementing D-Bus services in C++. It produces the C++ code to implement the interfaces defined in an XML input file.
D-Bus can be a complex and sometimes confusing technology that can take some time to learn. It can be a powerful tool, particularly when used with Qt. The details are outside the scope of what can be covered in this blog post, but you can learn more from the relevant Qt documentation.
I hope you found this blog post interesting. We haven't yet exhausted the list of lesser-known Qt commands. I plan to continue this series in future blog posts.