Results 1 to 3 of 3

Thread: QtDBus Qt Creator

  1. #1
    Join Date
    Dec 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QtDBus Qt Creator

    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 Code:
    1. QT += sql
    2. QT += dbus
    3. QT -= gui
    4. TARGET = configd
    5. CONFIG += dbus
    6. CONFIG += console
    7. CONFIG -= app_bundle
    8. TEMPLATE = app
    9. SOURCES += main.cpp \
    10. configdatabase.cpp \
    11. dbusconfig.cpp \
    12. watchconfig.cpp
    13. HEADERS += configdatabase.h \
    14. dbusconfig.h \
    15. watchconfig.h
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef DBUSCONFIG_H
    2. #define DBUSCONFIG_H
    3.  
    4. #include <QDBusAbstractAdaptor>
    5. #include <QCoreApplication>
    6. #include <QDBusMessage>
    7. #include <QDBusVariant>
    8.  
    9. #include "configdatabase.h"
    10. #include "watchconfig.h"
    11.  
    12. class DBusConfig : public QDBusAbstractAdaptor
    13. {
    14. Q_OBJECT
    15. Q_CLASSINFO("D-Bus Interface", "org.myinterface")
    16.  
    17. public:
    18. //
    19. // Constructor
    20. //
    21. DBusConfig(ConfigDatabase* db, QCoreApplication *app);
    22.  
    23. signals:
    24. //
    25. // Emitted when a value has changed on the watch list.
    26. //
    27. void valueChanged(const QString&);
    28.  
    29. public slots:
    30. //
    31. // Sets a configuration value
    32. //
    33. bool setValue(const QString&, const QDBusVariant&);
    34.  
    35. //
    36. // Gets a configuration value and send a reply back through dbus
    37. //
    38. void value(const QString&, const QDBusMessage&);
    39.  
    40. //
    41. // Adds a configuration value to a watch for change list
    42. //
    43. bool addWatch(const QString&);
    44.  
    45. private slots:
    46. //
    47. // Checks the watch list for changes
    48. //
    49. void checkWatchList(void);
    50.  
    51. private:
    52. //
    53. // Configuration values to watch for change
    54. //
    55. QList<WatchConfig> _watch;
    56.  
    57. //
    58. // Configuration Database
    59. //
    60. ConfigDatabase* _database;
    61. };
    62.  
    63. #endif // DBUSCONFIG_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QDBusConnection>
    3.  
    4. #include "configdatabase.h"
    5. #include "dbusconfig.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QCoreApplication a(argc, argv);
    10. ConfigDatabase db;
    11.  
    12. // Register configuration service
    13. if(!QDBusConnection::sessionBus().registerService("org.myservice"))
    14. {
    15. qFatal(qPrintable(QObject::tr("Could not register service on the session D-Bus.\n")));
    16. }
    17.  
    18. // Register Object
    19. DBusConfig *dbus = new DBusConfig(&db, &a);
    20. if(!QDBusConnection::sessionBus().registerObject("/Me/Config", dbus))
    21. {
    22. qFatal(qPrintable(QObject::tr("Could not register configuration object on the session D-Bus.\n")));
    23. }
    24.  
    25. return a.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtDBus Qt Creator

    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?

  3. #3
    Join Date
    Aug 2019
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QtDBus Qt Creator

    I had the same problem, correct export parameter solved it:

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

Similar Threads

  1. Qt Creator: File Makefile doesn't exist
    By earthling in forum Qt Tools
    Replies: 6
    Last Post: 4th November 2016, 04:44
  2. Cannot add custom widget to Qt Creator
    By djogon in forum Qt Tools
    Replies: 5
    Last Post: 30th April 2010, 11:15
  3. Remote debugging with Qt Creator
    By rodrigotavares in forum Qt Tools
    Replies: 4
    Last Post: 3rd February 2010, 19:15
  4. Replies: 0
    Last Post: 4th November 2009, 12:25
  5. Replies: 0
    Last Post: 18th February 2009, 20:17

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.