Hi,
I'm trying to create two Qt applications and connect them through DBus system.
The first application, the receiver, has a slot named "reload". The other application, the sender, must call this slot.
The receiver
The main.cpp:
MainWindow is a class that inherits from QMainWindow.
#include <QApplication>
#include <QTextCodec>
#include <QDBusConnection>
#include "MainWindow.hpp"
#include "DBusManager.hpp"
int main(int argc, char *argv[]) {
MainWindow *mainWindow = new MainWindow();
new DBusManager(mainWindow, &app);
mainWindow->show();
return app.exec();
}
#include <QApplication>
#include <QTextCodec>
#include <QDBusConnection>
#include "MainWindow.hpp"
#include "DBusManager.hpp"
int main(int argc, char *argv[]) {
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QApplication app(argc, argv);
MainWindow *mainWindow = new MainWindow();
new DBusManager(mainWindow, &app);
QDBusConnection::sessionBus().registerObject("/", &app);
mainWindow->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
The DBusManager.hpp:
#ifndef COMPONENT_DBUSMANAGER
#define COMPONENT_DBUSMANAGER
#include <QDBusAbstractAdaptor>
#include <QApplication>
#include "MainWindow.hpp"
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.simple-environment.sdesktop")
private:
MainWindow *mainWindow;
public:
public slots:
Q_NOREPLY void reload();
};
#endif
#ifndef COMPONENT_DBUSMANAGER
#define COMPONENT_DBUSMANAGER
#include <QDBusAbstractAdaptor>
#include <QApplication>
#include "MainWindow.hpp"
class DBusManager : public QDBusAbstractAdaptor {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.simple-environment.sdesktop")
private:
MainWindow *mainWindow;
public:
DBusManager(MainWindow *mainWindow, QApplication *parent);
public slots:
Q_NOREPLY void reload();
};
#endif
To copy to clipboard, switch view to plain text mode
The DBusManager.cpp:
#include "DBusManager.hpp"
/* Constructor */
this->mainWindow = mainWindow;
}
/* Public slots */
void DBusManager::reload() {
this->mainWindow->reload();
}
#include "DBusManager.hpp"
/* Constructor */
DBusManager::DBusManager(MainWindow *mainWindow, QApplication *parent) : QDBusAbstractAdaptor(parent) {
this->mainWindow = mainWindow;
}
/* Public slots */
void DBusManager::reload() {
this->mainWindow->reload();
}
To copy to clipboard, switch view to plain text mode
The sender
The sender, executes this code:
QDBusMessage message = QDBusMessage::createMethodCall("org.simple-environment.sdesktop", "/", "sdesktop", "reload");
QDBusConnection::sessionBus().call(message);
To copy to clipboard, switch view to plain text mode
I can compile both applications without problems, but when I execute them, the sender writes this through stderr:
process 14899: arguments to dbus_message_new_method_call() were incorrect, assertion "interface == NULL || _dbus_check_is_valid_interface (interface)" failed in file dbus-message.c line 1076.
This is normally a bug in some application using the D-Bus library.
QDBusConnection: error: could not send message to service "org.simple-environment.sdesktop" path "/" interface "sdesktop" member "reload"
What is wrong with this code?
Bookmarks