Results 1 to 3 of 3

Thread: DBus connection

  1. #1
    Join Date
    Jan 2009
    Posts
    5

    Default DBus connection

    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.
    Qt Code:
    1. #include <QApplication>
    2. #include <QTextCodec>
    3. #include <QDBusConnection>
    4.  
    5. #include "MainWindow.hpp"
    6. #include "DBusManager.hpp"
    7.  
    8. int main(int argc, char *argv[]) {
    9. QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    10. QApplication app(argc, argv);
    11.  
    12. MainWindow *mainWindow = new MainWindow();
    13. new DBusManager(mainWindow, &app);
    14. QDBusConnection::sessionBus().registerObject("/", &app);
    15.  
    16. mainWindow->show();
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    The DBusManager.hpp:
    Qt Code:
    1. #ifndef COMPONENT_DBUSMANAGER
    2. #define COMPONENT_DBUSMANAGER
    3.  
    4. #include <QDBusAbstractAdaptor>
    5. #include <QApplication>
    6.  
    7. #include "MainWindow.hpp"
    8.  
    9. class DBusManager : public QDBusAbstractAdaptor {
    10. Q_OBJECT
    11. Q_CLASSINFO("D-Bus Interface", "org.simple-environment.sdesktop")
    12.  
    13. private:
    14. MainWindow *mainWindow;
    15.  
    16. public:
    17. DBusManager(MainWindow *mainWindow, QApplication *parent);
    18.  
    19. public slots:
    20. Q_NOREPLY void reload();
    21. };
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    The DBusManager.cpp:
    Qt Code:
    1. #include "DBusManager.hpp"
    2.  
    3. /* Constructor */
    4.  
    5. DBusManager::DBusManager(MainWindow *mainWindow, QApplication *parent) : QDBusAbstractAdaptor(parent) {
    6. this->mainWindow = mainWindow;
    7. }
    8.  
    9. /* Public slots */
    10.  
    11. void DBusManager::reload() {
    12. this->mainWindow->reload();
    13. }
    To copy to clipboard, switch view to plain text mode 

    The sender

    The sender, executes this code:
    Qt Code:
    1. QDBusMessage message = QDBusMessage::createMethodCall("org.simple-environment.sdesktop", "/", "sdesktop", "reload");
    2. 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?

  2. #2
    Join Date
    Jan 2009
    Posts
    5

    Default Re: DBus connection

    Ok, now it doesn't write the error through stderr. The problem was that I have specified bad dbus inteface at sender.

    The new sender code:
    Qt Code:
    1. QDBusMessage message = QDBusMessage::createMethodCall("org.simple-environment.sdesktop", "/", "", "reload");
    2. QDBusConnection::sessionBus().call(message);
    To copy to clipboard, switch view to plain text mode 

    I run both applications but the receiver doesn't execute the "reload" slot

  3. #3
    Join Date
    Jan 2009
    Posts
    5

    Default Re: DBus connection

    The error is that I'm registering the object but not the service at receiver.

    The solution is, at main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include <QTextCodec>
    3. #include <QDBusConnection>
    4.  
    5. #include "MainWindow.hpp"
    6. #include "DBusManager.hpp"
    7.  
    8. int main(int argc, char *argv[]) {
    9. QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    10. QApplication app(argc, argv);
    11.  
    12. MainWindow *mainWindow = new MainWindow();
    13. new DBusManager(mainWindow, &app);
    14. QDBusConnection bus = QDBusConnection::sessionBus();
    15. bus.registerObject("/", &app);
    16. bus.registerService("org.simple-environment.sdesktop");
    17.  
    18. mainWindow->show();
    19.  
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. cannot share the database connection!!!!
    By cbarmpar in forum Qt Programming
    Replies: 13
    Last Post: 23rd September 2008, 14:42
  2. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 08:42
  3. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  4. Replies: 3
    Last Post: 2nd August 2007, 21:28
  5. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.