PDA

View Full Version : QtDBus Qt Creator



sngskunk
21st December 2009, 18: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:

org.freedesktop.DBus.Properties
org.freedesktop.DBus.Interospectable
(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
TEMPLATE = app
SOURCES += main.cpp \
configdatabase.cpp \
dbusconfig.cpp \
watchconfig.cpp
HEADERS += configdatabase.h \
dbusconfig.h \
watchconfig.h




#ifndef DBUSCONFIG_H
#define DBUSCONFIG_H

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

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

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

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

signals:
//
// 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);

private:
//
// 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
if(!QDBusConnection::sessionBus().registerService("org.myservice"))
{
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();
}

sngskunk
21st December 2009, 19: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?

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

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