View Full Version : QtDBus Qt Creator

21st December 2009, 19:31
I am currently using Qt Creator 1.3 to develop my project. But, I am having an issue with a QDBusAbstractAdaptor. It will build the project and run, and it will register the object with the session bus, and everything looks like it is working great.

Using the qdbusviewer I check the object that is on the session bus, it exists but my "D-Bus Interface" does not exists for the object. Only:

(my dbus interface) <-- MISSING

I am confused on what needs to be done for my interface to be exported on the dbus. Do I need to add something to be project file for qt creator to build the interface. Code is below:

QT += sql
QT += dbus
QT -= gui
TARGET = configd
CONFIG += dbus
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp \
configdatabase.cpp \
dbusconfig.cpp \
HEADERS += configdatabase.h \
dbusconfig.h \


#include <QDBusAbstractAdaptor>
#include <QCoreApplication>
#include <QDBusMessage>
#include <QDBusVariant>

#include "configdatabase.h"
#include "watchconfig.h"

class DBusConfig : public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Interface", "org.myinterface")

// Constructor
DBusConfig(ConfigDatabase* db, QCoreApplication *app);

// Emitted when a value has changed on the watch list.
void valueChanged(const QString&);

public slots:
// Sets a configuration value
bool setValue(const QString&, const QDBusVariant&);

// Gets a configuration value and send a reply back through dbus
void value(const QString&, const QDBusMessage&);

// Adds a configuration value to a watch for change list
bool addWatch(const QString&);

private slots:
// Checks the watch list for changes
void checkWatchList(void);

// Configuration values to watch for change
QList<WatchConfig> _watch;

// Configuration Database
ConfigDatabase* _database;

#endif // DBUSCONFIG_H

#include <QtCore/QCoreApplication>
#include <QDBusConnection>

#include "configdatabase.h"
#include "dbusconfig.h"

int main(int argc, char *argv[])
QCoreApplication a(argc, argv);
ConfigDatabase db;

// Register configuration service
qFatal(qPrintable(QObject::tr("Could not register service on the session D-Bus.\n")));

// Register Object
DBusConfig *dbus = new DBusConfig(&db, &a);
if(!QDBusConnection::sessionBus().registerObject("/Me/Config", dbus))
qFatal(qPrintable(QObject::tr("Could not register configuration object on the session D-Bus.\n")));

return a.exec();

21st December 2009, 20:16
Well I figured it out, I don't understand why it is designed this way.

Instead of me passing the DBusConfig object to the session bus, I should have passed, the QCoreApplication, which fixed the issue.

But why cant I just pass the DBusConfig object?

22nd August 2019, 09:15
I had the same problem, correct export parameter solved it:

QDBusConnection::sessionBus().registerObject("/obj", notificationAdaptor, QDBusConnection::ExportAllContents);