[PyQt] How to call DBus method with UInt32 arg?
Evade Flow
evadeflow at gmail.com
Mon Dec 10 18:41:36 GMT 2012
Hi, all. Does anyone have experience trying to pass UInt32 arguments to
a DBus service using PyQt4.QtDBus? The program appended below generates
the following error:
% python build_connection.py 0 0 0 1234
Call failed: No such method 'buildConnection' in interface
'com.acme.Audio.Connection' at object path
'/com/acme/Audio/Connection' (signature '(i)(i)(i)i')
I think it's failing because the actual signature of the method to be
called is '(i)(i)(i)u' [??] (Don't ask why the designers of this
interface wrapped a DBus struct around every int--I have no idea. `:-@)
Can anyone confirm whether passing unsigned 32-bit arguments is possible
with my version of PyQt4/SIP:
>>> import PyQt4.QtCore
>>> PyQt4.QtCore.PYQT_VERSION_STR
'4.9.3'
>>> PyQt4.QtCore.PYQT_VERSION
264451
>>> import sip
>>> sip.SIP_VERSION_STR
'4.13.3'
>>> sip.SIP_VERSION
265475
Is there some way I can coerce the last arg to the right type?
--------------------
#!/usr/bin/env python
from PyQt4 import QtDBus
from PyQt4.QtCore import QCoreApplication
if __name__ == '__main__':
import sys
from os.path import basename
if len(sys.argv) != 5:
print("Usage: %s <sender> <source> <sink> <connID>" %
(basename(sys.argv[0]),))
sys.exit(1)
sender = int(sys.argv[1])
source = int(sys.argv[2])
sink = int(sys.argv[3])
conn_id = int(sys.argv[4])
app = QCoreApplication(sys.argv)
bus = QtDBus.QDBusConnection.connectToBus(
"tcp:host=192.168.0.1,port=6668",
"myConnection"
)
iface = QtDBus.QDBusInterface(
'com.acme.Audio',
'/com/acme/Audio/Connection',
'com.acme.Audio.Connection',
bus
)
if not iface.isValid():
sys.stderr.write("Invalid interface: %s\n" % bus.lastError().message())
sys.exit(1)
sender_ = QtDBus.QDBusArgument()
sender_.beginStructure()
sender_.add(sender)
sender_.endStructure()
source_ = QtDBus.QDBusArgument()
source_.beginStructure()
source_.add(source)
source_.endStructure()
sink_ = QtDBus.QDBusArgument()
sink_.beginStructure()
sink_.add(sink)
sink_.endStructure()
msg = iface.call('buildConnection', sender_, source_, sink_, conn_id)
reply = QtDBus.QDBusReply(msg)
if not reply.isValid():
sys.stderr.write("Call failed: %s\n" % reply.error().message())
sys.exit(1)
#else:
#sys.stdout.write("Reply was: %s\n" % reply.value())
More information about the PyQt
mailing list