[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: Returning struct with Qt DBus?
From: Florian Bruhin <me () the-compiler ! org>
Date: 2022-08-18 9:14:41
Message-ID: 20220818091441.r4xryr66rh2zaz2g () aragog
[Download RAW message or body]
Hey,
On Wed, Mar 24, 2021 at 06:31:19PM +0100, Florian Bruhin wrote:
> 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?
I finally have something that works - turns out that the solution is to
not use the return value at all, and instead send a reply to the bus
manually:
@pyqtSlot(QDBusMessage)
def GetServerInformation(self, msg: QDBusMessage):
QDBusConnection.sessionBus().send(msg.createReply(["name", "vendor", \
"v0.0.1", "1.2"]))
Huge thanks to u/SomethingOfAGirl on Reddit, who contacted me with the same
problem (and later solution).
Florian
--
me@the-compiler.org | https://www.qutebrowser.org
https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic