Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dbus adaptor using qt5
Qt 6.11 is out! See what's new in the release blog

Dbus adaptor using qt5

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skylendar
    wrote on last edited by
    #1

    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.

    CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    project(dbus)

    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)

    main.h

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

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

    public:

    Main(QObject *parent);

    public slots:

    QString Test();
    };
    #endif

    main.cpp

    #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);
    qapp.exec();

    }

    thx again for your help

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skylendar
      wrote on last edited by
      #2

      Does it exist a working example of QDbusAdaptor for Qt5 ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skylendar
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved