[PyQt] How to create an array of non-var struct with PyQt + QDBus?

Kovid Goyal kovid at kovidgoyal.net
Mon Oct 27 01:59:45 GMT 2014


I recommend you use the python DBUS bindings instead, they are more
capable than the PyQt ones, and generally nicer to use, since they dont
have to deal with the limitations of a C++ API. Another limitation of
the PyQt bindings is you cannot create properties that have non-basic
signatures.

See this http://qt-project.org/wiki/PySide_DBus_Integration
for a simple example of how to integrate the python dbus bindings with
the Qt event loop and see this: https://github.com/kovidgoyal/calibre/blob/master/src/calibre/gui2/sni.py

for a more complex example, that includes properties/methods with
complex type signatures, and linking between Qt and DBUS signals.

Note that, to export properties, you will need a modified version of
dbus.service, which you can find here: 
https://github.com/kovidgoyal/calibre/blob/master/src/calibre/utils/dbus_service.py

Remember to change is_py2 if you are running on python 3.

Kovid.

On Mon, Oct 27, 2014 at 06:05:20AM +0800, Xinkai wrote:
> Hi,
> 
> I am stuck with trying to create a QDBusMessage with an array of struct,
> something like "a(ii)".  I tried the following on Python 3.4.2 + PyQt 5.3.2:
> 
> 
> @pyqtSlot(QDBusMessage)
> def process(self, msg):
>     # Attempt 1
>     a1 = QDBusArgument()
>     a1.add(1, QMetaType.Int)
>     a1.add(2, QMetaType.Int)
> 
>     a2 = QDBusArgument()
>     a2.add(1, QMetaType.Int)
>     a2.add(2, QMetaType.Int)
> 
>     reply = msg.createReply([
>         [a1, a2],
>     ])
>     # Result: the signature is "av", not "a(ii)"
> 
> 
>     # Attempt 2
>     args = QDBusArgument()
>     args.beginArray(??)
> 
>     args.endArray()
>     # Result: No way to register a custom QMetaType. I understand there
> might be a Qt type that happens to be int/int, but I am looking for a
> more generic way to do this. I am actually dealing with something more
> complex than "a(ii)".
> 
> 
> Is there any way to do this? Or I hit the limitation of PyQt's QDBus, if
> so, any suggestions?
> 
> 
> Thanks in advance,
> 
> Xinkai
> 
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 
> !DSPAM:3,544d704918271087514679!
> 
> 

-- 
_____________________________________

Dr. Kovid Goyal 
http://www.kovidgoyal.net
http://calibre-ebook.com
_____________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141027/e568fc0f/attachment.sig>


More information about the PyQt mailing list