How to pass an array of string to dbus in PyQt5? [duplicate]

冷暖自知 提交于 2020-01-15 06:45:50

问题


I'm trying to make a dbus call using python3.4 and pyqt5.4 to a java-written daemon, the signature of the daemon for the method I'm calling is asa{sv}

The call I'm doing is

fpiudaemon = QDBusInterface("it.libersoft.FirmapiuDInterface", "/it/libersoft/FirmapiuD", interface='it.libersoft.FirmapiuDInterface' , parent=None)
result = fpiudaemon.call('sign',filepath,options)

Where

print (filepath) -> ['/home/svalo/programmi/devel/pythondeps']
print (options) -> {'pin': '12345678', 'outdir': '/home/svalo/programmi/devel/firmapiu-gui'}

print(type(filepath)) -> <class 'list'>
print(type(options)) -> <class 'dict'>

However when I monitor dbus what I get is

method call sender=:1.242 -> dest=it.libersoft.FirmapiuDInterface serial=67 path=/it/libersoft/FirmapiuD; interface=it.libersoft.FirmapiuDInterface; member=sign
   array [
      variant          string "/home/svalo/programmi/devel/firmapiu-gui/pythondeps"
   ]
   array [
      dict entry(
         string "outdir"
         variant             string "/home/svalo/programmi/devel/firmapiu-gui"
      )
      dict entry(
         string "pin"
         variant             string "12345678"
      )
   ]

What i'd like to get is

method call sender=:1.242 -> dest=it.libersoft.FirmapiuDInterface serial=67 path=/it/libersoft/FirmapiuD; interface=it.libersoft.FirmapiuDInterface; member=sign
   array [
      string "/home/svalo/programmi/devel/libersoft/firmapiu-gui/pythondeps"
   ]
   array [
      dict entry(
         string "outdir"
         variant             string "/home/svalo/programmi/devel/libersoft/firmapiu-gui"
      )
      dict entry(
         string "pin"
         variant             string "12345678"
      )
   ]

That is I expect python to send an array of strings and instead it sends an array of variants containing strings.

The daemon devel wrote a simple client in java and it works honoring the signature

What am I missing here?


回答1:


According to the dbus-spec, the string-type is defined as follows:

STRING 115 (ASCII 's') UTF-8 string (must be valid UTF-8). Must be nul terminated and contain no other nul bytes.

Which seems to imply that you should pass a UTF-8 encoded bytes object, rather than a unicode object.

EDIT:

You might need to pass this as a QByteArray:

QtCore.QByteArray(unicode_string.encode('utf-8'))



回答2:


5 years later, an answer appears!

You can specify the type signature of a dbus argument with QDbusArgument. Here's an example:

filepath = QDBusArgument()
filepath.add(['/home/svalo/programmi/devel/pythondeps'], QMetaType.QStringList)
result = fpiudaemon.call('sign',filepath,options)

Obviously make sure that your data can be converted directly into the type you specified.



来源:https://stackoverflow.com/questions/28075484/how-to-pass-an-array-of-string-to-dbus-in-pyqt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!