This forum has been archived. All content is frozen. Please use KDE Discuss instead.

dbus adaptor in qt5

Tags: None
(comma "," separated)
skyly
Registered Member
Posts
24
Karma
0

dbus adaptor in qt5

Wed Aug 13, 2014 10:41 pm
Thx for reading and possibly answering this post

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

What's wrong ?

### 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
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: dbus adaptor in qt5

Thu Aug 14, 2014 8:00 am
If you don't get a response here, you may wish to try asking on the KDE Devel mailing list, where someone might be able to answer your question. It can be emailed at kde-devel@kde.org. You could also try using the KDBusAddons framework.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
skyly
Registered Member
Posts
24
Karma
0

Re: dbus adaptor in qt5

Wed Aug 20, 2014 2:38 pm
I did as you suggested and also subscribed to the relevant forum at qt-project.org, but I got nothing, not even a acknowledgement of the issue.

Thank you for your help :D
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: dbus adaptor in qt5

Thu Aug 21, 2014 7:36 am
Could you please upload a tarball of your source code somewhere, and explain what exactly is failing?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
skyly
Registered Member
Posts
24
Karma
0

Re: dbus adaptor in qt5

Thu Aug 21, 2014 1:54 pm
Sure, you can get it from http://skylendar.kde.org/dbus.tar.bz2, then run cmake and make as usual. You should get an executable named main.

Run main. It doesn't display anything, but if you launch qdbusviewer, a dbus bus named org.kde.main, should be displayed. It is not the case. It works with kde4 but not with qt5/kf5.

Is it a QDBusAdaptor bug somewhere, or a bug in my small program ?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: dbus adaptor in qt5

Sat Aug 23, 2014 2:11 am
So it compiles, but does not list on D-Bus? Have you tried looking into KDBus, which is provided by one of the Frameworks?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
skyly
Registered Member
Posts
24
Karma
0

Re: dbus adaptor in qt5

Sat Aug 23, 2014 1:48 pm
will try, but all the involved resources of my program use qt5, so it seems to be a qt5 problem. In addition, kf5 crashes on my opensuse box.

Why a dbus bus can only be seen by a kf5 app and not by the native and relevant tool designed for that, qdbusviewer ?

thx anyway for the tip.
skyly
Registered Member
Posts
24
Karma
0

Re: dbus adaptor in qt5

Sun Aug 24, 2014 1:59 pm
Also tried the standard dbus-send command, but I got the same thing. Something seems wrong with QDBusAdaptor, which is a key class of the qt dbus stack. Weird weird :|

Does it exist a working example of QDBusAdaptor for qt5 ? The one provided with the qt5 doc doesn't work as swell.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: dbus adaptor in qt5

Tue Nov 04, 2014 4:17 am
That is extremely unusual - if the included Qt examples don't work then something is very wrong. Is qdbus (as provided with Qt 5) able to work as a client?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
wduncan
Registered Member
Posts
1
Karma
0

Re: dbus adaptor in qt5

Sun Aug 16, 2015 7:50 pm
A year late -- but the reason this is not working is not a build issue. Need to also register the serviceName. New main with fixes follows.

Code: Select all
#include "main.h"
#include <QCoreApplication>
#include "mainadaptor.h"

Main::Main(QObject *parent) : QObject(parent)
{
  new MainAdaptor(this);
  QDBusConnection connection = QDBusConnection::sessionBus();
   
  connection.registerObject("/", this);
  int dbusClassInfoIndex = this->metaObject()->indexOfClassInfo("D-Bus Interface
");
   
  QString dbusServiceName = this->metaObject()->classInfo(dbusClassInfoIndex).va
lue();
  connection.registerService(dbusServiceName);

}

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

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



Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]