Important: Please read the Qt Code of Conduct -

Dbus adaptor using qt5

  • Hi there and thx for reading and possibly answering this post if you can.

    I'm striving to open a dbus adaptor with qt5. I provide you with a working example below.
    The example program works, but I don't see any available bus with qdbusviewer. It should be 'org.kde.main' (see code)

    What's wrong ? Is there a bug in Qt5 DBus module ?

    P.S. The example provided with the QDbusAdaptor Qt5 documentation doesn't work anymore with qt5.
    It only works with qt4.


    cmake_minimum_required(VERSION 2.8)

    find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus)

    change path here !

    set(Q "/opt/Qt5.3.1/5.3/gcc_64/include/")
    include_directories(${Q}QtCore ${Q}DBus)

    set(SRC main.cpp)

    qt5_wrap_cpp(MOC main.h)

    qt5_generate_dbus_interface(main.h main.xml)

    qt5_add_dbus_adaptor(SRC1 main.xml main.h Main)

    add_executable(main ${SRC} ${SRC1} ${MOC})

    target_link_libraries(main Qt5::Core Qt5::DBus)


    #ifndef MAIN
    #define MAIN
    #include <QtDBus/QtDBus>

    class Main: public QObject
    Q_CLASSINFO("D-Bus Interface", "org.kde.main")


    Main(QObject *parent);

    public slots:

    QString Test();


    #include "main.h"
    #include <QCoreApplication>
    #include "mainadaptor.h"

    Main::Main(QObject *parent) : QObject(parent)
    new MainAdaptor(this);
    QDBusConnection::sessionBus().registerObject("/Main", this);

    QString Main::Test() { return "Ok"; }

    int main(int argc, char *argv[])
    QCoreApplication qapp(argc, argv);
    Main Main(&qapp);


    thx again for your help

  • Does it exist a working example of QDbusAdaptor for Qt5 ?

  • QDbusAdaptor is maybe an obsolete class. In that case, it should be declared as such.

Log in to reply