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
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
To copy to clipboard, switch view to plain text mode
#ifndef DBUSCONFIG_H
#define DBUSCONFIG_H
#include <QDBusAbstractAdaptor>
#include <QCoreApplication>
#include <QDBusMessage>
#include <QDBusVariant>
#include "configdatabase.h"
#include "watchconfig.h"
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.myinterface")
public:
//
// Constructor
//
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
#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
To copy to clipboard, switch view to plain text mode
#include <QtCore/QCoreApplication>
#include <QDBusConnection>
#include "configdatabase.h"
#include "dbusconfig.h"
int main(int argc, char *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);
{
qFatal
(qPrintable
(QObject::tr("Could not register configuration object on the session D-Bus.\n")));
}
return a.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks