qmake and D-Bus

Something I did not find documented anywhere: a sensible way to generate QtDBus adaptor and interface classes from introspection data with qdbusxml2cpp. I only found hacks using system() and custom targets to accomplish the feat.

I though to myself that there must be a saner, better way, and while looking at the qmake generated Makefile, I noticed some interesting includes. After some investigation, I found "magic" variables DBUSINTERFACES and DBUSADAPTORS. The introspect files should be named servicename.xml and listed in the variables, and qmake will do all the magic for you.

With these variables, it is really easy to generate the helper classes on-demand. Just remember to include the generated header in some code file, otherwise compilation will choke.

TEMPLATE = app
QT = core dbus
TARGET = qtdbus
DBUS_ADAPTORS = fi.inz.hello.xml
SOURCES = hello.cpp main.cpp
HEADERS = hello.h

With this simple .pro file qmake autogenerates the adaptor on build.

To see other files from the example, see fi.inz.hello.xml hello.cpp hello.h main.cpp qtdbus.pro