System information:
- QT5.10
- Ubuntu 16.04
With QtDBus, and using the following XML, I generated the xyz_interface.hpp
<!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.blah.XYZ">
<signal name="Event">
<arg name="event_json" type="s" direction="out"/>
</signal>
<method name="AuthenticateUser">
<arg name="auth_req_json" type="s" direction="in"/>
<arg name="result" type="s" direction="out"/>
</method>
</interface>
</node>
After creating the interface, and connecting to the interface's signal;
com::blah::Xyz interface = new com::blah::Xyz("com.blah.XYZ", "/com/blah/XYZ", QDBusConnection::systemBus(), this);
connect(interface , &com::blah::Xyz::Event, this, &SomeClass::HandleEvents)
I'm unable to trigger the breakpoint inside the function SomeClass::HandleEvents when sending a signal from Xyz by through command line with dbus-send;
dbus-send --system --type=signal /com/blah/Xyz com.blah.XYZ.Event string:"hello"
using dbus-monitor --system, I can see the signal is being correctly emitted.
Then, in the unit tests, I created a test signal as;
QDBusMessage xyz_signal = QDBusMessage::createSignal(
"/com/blah/XYZ", "com.blah.XYZ", "Event");
xyz_signal << "hello";
ASSERT_TRUE(connection.send(xyz_signal ));
That also failed to trigger the breakpoint.
After hours of searching for a solution, i gave up and created some fake python dbus services that emitted the Event signal on command (replaced dbus-send) and voila.. the breakpoint was triggered and signal was caught! (not a single change to the QT dbus code)
The fact that i'm able to receive a signal emitted from python code, leads me to think that my dbus-send --system --type=signal is wrongly formatted, but can't seem to fix it.
here's the python code;
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
class XyzService(dbus.service.Object):
@dbus.service.method("com.blah.Xyz",
in_signature='s', out_signature='s')
def AuthenticateUser(self, auth_req_json):
print (str("hello_message"))
return '''
{
"AuthenticationResponce" : "SUCCESS"
}
'''
@dbus.service.method("com.blah.Xyz",
in_signature='s')
def EmitEvent(self, str):
self.Event(str)
@dbus.service.signal('com.blah.Xyz', signature='s')
def Event(self, event_json):
# The signal is emitted when this method exits
# You can have code here if you wish
pass
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
system_bus = dbus.SystemBus()
name = dbus.service.BusName("com.blah.Xyz", system_bus)
object = XyzService(system_bus, '/com/blah/Xyz')
mainloop = gobject.MainLoop()
print "Running example service."
mainloop.run()
Update
I just found out that if I create the interface with empty strings for path and name, then I am able to receive the signals sent by command line dbus-send
com::blah::Xyz interface = new com::blah::Xyz("", "", QDBusConnection::systemBus(), this);
Also the unit test above is passing.
but now i'm unable to call the method AuthenticateUser! This is very confusing
Update 2
I was able to reproduce the issue with the RemoteControlledCar dbus example provided by QT found here; https://code.qt.io/cgit/qt/qtbase.git/tree/examples/dbus/remotecontrolledcar?h=5.10
In controller.cpp, in the constructor, i added the following;
Controller::Controller(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
car = new org::example::Examples::CarInterface("org.example.CarExample", "/Car",
QDBusConnection::sessionBus(), this);
// added signal listener
connect(car, &org::example::Examples::CarInterface::crashed,this,[](){qDebug("hello signal");});
startTimer(1000);
}
when triggering the signal with dbus-send, the message hello signal is not printed. But when I change the service path and name to empty string, then I successfully receive the signal;
car = new org::example::Examples::CarInterface("", "",
QDBusConnection::sessionBus(), this);
from command line
dbus-send --session --type=signal /Car org.example.Examples.CarInterface.crashed
Cheers, Simon