PDA

View Full Version : QDBus signal not received



sajmplus
19th January 2018, 13:28
Hi, I have problem with QDBus module. I want to receive signal from my other application, signal is emited (listed in dbus-monitor) however application slot is not triggered:

receiver.h


#ifndef RECEIVER_H
#define RECEIVER_H

#include <iostream>
#include <QObject>

class Receiver : public QObject {
Q_OBJECT
public:
~Receiver() { std::cout << "Receiver destoryed."; }
public slots:
void receive() {
std::cout << "Received!";
}
};

#endif // RECEIVER_H


main.cpp


#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusInterface>
#include <iostream>
#include "receiver.h"

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto bus = QDBusConnection::connectToBus(QDBusConnection::Ses sionBus,
"ControllerBoard");
if(bus.isConnected()) {
std::cout << "Bus connected." << std::endl;
} else {
std::cout << QString("Bus not conected: %1").arg(bus.lastError().message()).toStdString()
<< std::endl;
}

auto recv = new Receiver;
auto interface = new QDBusInterface("com.ControllerBoard",
"/",
"com.ControllerBoard.Buttons",
bus, &a);

if(interface->isValid()) {
QObject::connect(interface, SIGNAL(PowerButtonPushed()), recv, SLOT(receive()));
} else {
std::cout << QString("Interface not valid: %1").arg(interface->lastError().message()).toStdString()
<< std::endl;

}

return a.exec();
}


I ran application with QDBUS_DEBUG=1, here is output:


QDBusConnectionPrivate(0x7fe7780032f0) : connected successfully
Bus connected.
QDBusConnectionPrivate(0x7fe7780032f0) got message (signal): QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.104") )
QDBusConnectionPrivate(0x7fe7780032f0) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("com.ControllerBoard") )
QDBusConnectionPrivate(0x7fe7780032f0) got message reply: QDBusMessage(type=MethodReturn, service="org.freedesktop.DBus", signature="s", contents=(":1.98") )
QDBusConnectionPrivate(0x7fe7780032f0) sending message: QDBusMessage(type=MethodCall, service="com.ControllerBoard", path="/", interface="org.freedesktop.DBus.Introspectable", member="Introspect", signature="", contents=() )
QDBusConnectionPrivate(0x7fe7780032f0) got message reply: QDBusMessage(type=MethodReturn, service=":1.98", signature="s", contents=("<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.ControllerBoard.Buttons">
<signal name="PowerButtonPushed"/>
<signal name="PowerButtonReleased"/>
<signal name="ScalesButtonPushed"/>
<signal name="ScalesButtonReleased"/>
<signal name="TimerButtonPushed"/>
<signal name="TimerButtonReleased"/>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface_name" type="s" direction="in"/>
<arg name="values" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface_name" type="s" direction="out"/>
<arg name="changed_properties" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
<arg name="invalidated_properties" type="as" direction="out"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" type="s" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping"/>
<method name="GetMachineId">
<arg name="machine_uuid" type="s" direction="out"/>
</method>
</interface>
</node>
") )
QDBusConnectionPrivate(0x7fe7780032f0) Adding rule: "type='signal',sender='org.freedesktop.DBus',interf ace='org.freedesktop.DBus',member='NameOwnerChange d',arg0='com.ControllerBoard'"
QDBusConnectionPrivate(0x7fe7780032f0) Adding rule: "type='signal',sender='com.ControllerBoard',path='/',interface='com.ControllerBoard.Buttons',member=' PowerButtonPushed'"
QDBusConnectionPrivate(0x7fe7780032f0) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("com.ControllerBoard") )
QDBusConnectionPrivate(0x7fe7780032f0) got message reply: QDBusMessage(type=MethodReturn, service="org.freedesktop.DBus", signature="s", contents=(":1.98") )
QDBusConnectionPrivate(0x7fe7780032f0) Watching service "com.ControllerBoard" for owner changes (current owner: ":1.98" )
QDBusConnectionPrivate(0x7fe7780032f0) got message (signal): QDBusMessage(type=Signal, service=":1.98", path="/", interface="com.ControllerBoard.Buttons", member="PowerButtonPushed", signature="", contents=() )