Returning struct with Qt DBus?

Gottfried Müller gottfried.mueller at
Thu Mar 25 05:55:49 GMT 2021

Hello Florian,

I made some experiments with DBus and Python three years ago. I encoded
the message data. I used it to transfer a python dictionary.

import pickle
import binascii

def pyDBusEncode(dataToSend):
     pickledData = pickle.dumps(dataToSend)
     return str(binascii.hexlify(pickledData), 'utf-8')

def pyDBusDecode(dataReceived):
     binData = bytearray(dataReceived, 'utf-8')
     pickledData = binascii.unhexlify(binData)
     return pickle.loads(pickledData)

Maybe it is an answer and it works today too


Am 24.03.21 um 18:31 schrieb Florian Bruhin:
> Hey,
> I'm currently trying to write a simple DBus notification server for end
> to end tests.
> If I run the attached server (after killing my usual notification
> daemon), invoking e.g. GetCapabilities (which returns a list of strings)
> works fine:
>      $ dbus-send --session --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.GetCapabilities
>      method return time=1616606628.700096 sender=:1.451 -> destination=:1.457 serial=16 reply_serial=2
>         array [
>            string "actions"
>         ]
> However, I can't figure out how to get GetServerInformation to work,
> which is supposed to return a struct of four strings ("ssss" as DBus
> signature). I've tried returning a QDBusArgument and using:
>      @pyqtSlot(QDBusMessage, result="QDBusArgument")
>      def GetServerInformation(self, message):
>          arg = QDBusArgument()
>          arg.beginStructure()
>          arg.add("qutebrowser")
>          arg.add("notification test server")
>          arg.add("v13.37")
>          arg.add("1.2")
>          arg.endStructure()
>          return arg
> But that doesn't seem to work:
>      $ dbus-send --session --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.GetServerInformation
>      Error org.freedesktop.DBus.Error.UnknownMethod: No such method 'GetServerInformation' in interface 'org.freedesktop.Notifications' at object path '/org/freedesktop/Notifications' (signature '')
> If possible, I'd prefer using Qt DBus only rather than the python-dbus
> integration.
> Any idea how I can get this to work? Or is this just not possible
> without being able to register Qt metatypes or something?
> Thanks,
> Florian

More information about the PyQt mailing list