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

Xinkai yeled.nova at gmail.com
Tue Oct 28 18:03:06 GMT 2014


On 10/27/2014 09:59 AM, Kovid Goyal wrote:
> 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!
>>
>>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Thanks for the information about the dbus-python library.  However, I
found the project page, it says: /dbus-python might not be the best
D-Bus binding for you to use. dbus-python does not follow the principle
of "In the face of ambiguity, refuse the temptation to guess", and can't
be changed to not do so without seriously breaking compatibility./

That concered me, so I ended up writing a C++ extension with sip, to
register QMetaType. It worked fine and I felt it was easy enough to do.

Anyone having a similar problem can see my code at:
https://github.com/Xinkai/XwareDesktop/tree/master/src/frontend/Extensions


Cheers,

Xinkai/
/////
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141029/77d3f2b8/attachment.html>


More information about the PyQt mailing list