qmake and D-Bus

February 18, 2011 on 9:58 pm | In geeky | 5 Comments

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 DBUS_INTERFACES and DBUS_ADAPTORS. 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

5 Comments »

RSS feed for comments on this post. TrackBack URI

  1. emarkus says:

    thanks!

    and it is *really* important to include "hello_adaptor.h" somewhere! even if you don't need it for testing in the first step! If you don't include it, it won't be generated by qmake. and then the hello_adaptor.cpp will not compile to object file...

  2. [...] итоге раскопок наткнулся на топик, где сказано, что нужно в .pro-файле просто прописать [...]

  3. Roland says:

    Can you auto-regenerate the xml file with this too somewhow? That part doesn't work for me.

  4. smk says:

    This is used to generate C++ code from .xml, not to generate the .xml. XML is the source file.

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress.
Entries and comments feeds. Valid XHTML and CSS. ^Top^