本文介绍了如何在PyQt5中将字符串数组传递给dbus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python3.4和pyqt5.4到Java编写的守护程序进行dbus调用,所调用方法的守护程序签名为asa{sv}

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}

我正在打的电话是

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

哪里

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'>

但是,当我监视dbus时,我得到的是

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"
      )
   ]

我想得到的是

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"
      )
   ]

我希望python发送一个字符串数组,而是发送一个包含字符串的变体数组.

守护进程devel用Java编写了一个简单的客户端,并且可以兑现签名

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

我在这里想念什么?

推荐答案

5年后,答案出现了!

5 years later, an answer appears!

您可以使用QDbusArgument指定dbus参数的类型签名.这是一个示例:

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.

这篇关于如何在PyQt5中将字符串数组传递给dbus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 15:30