Qt DBus XML howto
-
Hello, I want to develop a Qt5 QtDBus app GUI, for safely erasing HDD's. They have told me that QtDBus is the best way, but I don't know exactly where to start. BTW, the have told be I should use XML files and parse them using qdbusxml2cpp, but I don't know how this works.
Could anyone please explain me more or less how QtDBus XML files work? Thank you!
-
Hi,
Did you already went through the QtDBus module documentation ?
Beside explaining the concepts it also describe the tools and there are several examples you can check.
-
Hi!
Maybe a little late, but I want to share it with future users on how to integrate DBus in Qt.
When you need to send objects via DBus, your class must be described in XML so that Qt can generate the interface and adaptor for sending and receiving those objects. For example, with
MyClass
defined, you can runqdbuscpp2xml MyClass.h -o xmlMyClass.xml
. If MyClass methods return or get standard parameters (supported types listed here: https://doc.qt.io/qt-6/qdbustypesystem.html),qdbuscpp2xml
will generate everything for you. However, if the methods involve unsupported types, such as another custom object, you'll need to manually edit the XML file.Once your class is described in the XML file, use
qdbusxml2cpp
to generate the interface and adaptor, then connect them to the Bus. From there, you can use the interface to send and receive data.I haven't gone into full detail here to keep the comment concise, but I’ve written a blog post that covers this process more thoroughly, including how to edit the XML file for
qdbusxml2cpp
to generate a complete interface and adaptor. The post is based on Qt6, but it should also work with Qt5: https://scythe-studio.com/en/blog/how-to-use-d-bus-with-qt-6I hope this helps!