[PyQt] Passsing Unsigned Int to DBus

Bo Møller Petersen kemibo at gmail.com
Mon Feb 11 16:38:58 GMT 2019


I was looking af http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html
and got the impression that QVariant was not available when using python 3.

Anyway using you code I get the following error:
QDBusMarshaller: cannot add a null QDBusVariant
QDBusConnection: error: could not send message to service
"org.kde.Solid.PowerManagement.PolicyAgent" path
"/org/kde/Solid/PowerManagement/PolicyAgent" interface
"org.kde.Solid.PowerManagement.PolicyAgent" member "AddInhibition":
Marshalling failed: Variant containing QVariant::Invalid passed in arguments

I must admit i'm a bit lost on where the QVariant picked up the
QVariant::Invalid. Any pointer on where to look?

Bo



On Sun, Feb 10, 2019 at 7:19 PM Phil Thompson <phil at riverbankcomputing.com>
wrote:

> On 10 Feb 2019, at 5:55 pm, Bo Møller Petersen <kemibo at gmail.com> wrote:
> >
> > I'm trying to use PyQt5's DBus module to interact with the KDE
> PowerManagerAgent on a linux system. When calling the AddInhibition method
> I need to send the first paramter as an uint32 (Unsigned int), but the code
> sends the value as a singed int.
> >
> > The code is written using Python 3 and using Pyqt5
> >
> > class PowerChangeInhibitor:
> >     def __init__(self):
> >         self.dBusService = 'org.kde.Solid.PowerManagement.PolicyAgent'
> >         self.dBusPath = '/org/kde/Solid/PowerManagement/PolicyAgent'
> >         self.dBusInterface = 'org.kde.Solid.PowerManagement.PolicyAgent'
> >         self.cookies = []
> >
> >     def ActivateInhibition(self, interruptSession, changeProfile,
> changeScreenSettings,who, reason):
> >
> >
> >         self.dBus = QtDBus.QDBusConnection.sessionBus()
> >         if interruptSession:
> >             #dBusInterface = QtDBus.QDBusInterface(self.dBusService,
> self.dBusPath,'' , self.dBus)
> >             #reply = dBusInterface.call('AddInhibition',1,who,reason)
> >
> >             msg = QtDBus.QDBusMessage.createMethodCall(self.dBusService,
> self.dBusPath,self.dBusInterface,'AddInhibition')
> >
> >             #unsignedValue = 1
>          # writes 1 but typed as int32
> >             #unsignedValue = ctypes.c_uint(1)
>         # Type not registered
> >             #unsignedValue = struct.unpack_from("I", struct.pack("i",
> 1))        # Type not registered
> >             #unsignedValue = QtCore.QByteArray(b'0x01')[0]
>          # Type not registered
> >             #unsignedValue =  bytes(1)
>          # Type not registered
> >             #unsignedValue = QtDBus.QDBusVariant(1)
>         # array of bytes "0x01"
> >             #unsignedValue = QtDBus.QDBusVariant(1)[0]
>          # QDBusVariant does not support indexing
> >             #unsignedValue =
> QtDBus.QDBusVariant().setVariant(ctypes.c_uint(1))  # Variant contained
> QVariantInvalid
> >             unsignedValue =  QtDBus.QDBusVariant(ctypes.c_uint(1))
>           # Type not registered
> >
> >             msg << unsignedValue << who << reason
> >             reply = QtDBus.QDBusReply(self.dBus.call(msg))
> >             if reply.isValid():
> >                 self.cookies.append(reply.value())
> >
> >
> > I have commented out previous attempts with their results on the right.
> Using dbus-monitor I can see that the part where i'm struggeling is getting
> QDBusInterface to emit the desired UNIT32 type info.
> >
> > Any pointers on how I pass an unsigned int as an argument to my
> QDBusMessage ?
>
> Use QVariant.convert()...
>
> qvar = QVariant(ctypes.c_uint(1))
> qvar.convert(QVariant.UInt)
> unsignedValue = QtDBus.QDBusVariant(qvar)
>
> Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190211/3c8daffb/attachment.html>


More information about the PyQt mailing list