[PyQt] Type map for python to Qt?

Shaheed Haque srhaque at theiet.org
Fri Feb 3 22:19:08 GMT 2017

A slightly related question. For my SIP generator, I'm working on
partially-automated %MappedType support for QMap/QList/Q<otherstuff> and
also fixed size arrays (1D for now, maybe more later). For the fixed size
arrays, I'm looking for input on how to represent them in Python, i.e. as
tuples or lists. My instinct is to go with tuples, but would be interested
to hear other ideas.

Also, I see the SIP5 roadmap talks about fixed array support: what is the
plan there?

On 2 February 2017 at 19:31, Cody Scott <cody at perspexis.com> wrote:

> I wouldn't worry about breaking compatibility. I'd be surprised if people
> are actually passing Python tuples to Qt, since they don't come across as a
> list and it is easy enough to convert to a list before passing the value to
> Qt. And surely if they do now come across as a list then that would be
> better (though might require a small code change).
> On Thu, Feb 2, 2017 at 12:12 PM, Phil Thompson <
> phil at riverbankcomputing.com> wrote:
>> On 2 Feb 2017, at 5:02 pm, Russell Warren <russ at perspexis.com> wrote:
>> >
>> > Conversions are implemented only if there is a direct equivalent,
>> everything else gets converted to a PyQt_PyObject. You could perhaps make
>> the case for the date/time types.
>> >
>> > datetime definitely might be nice, but the one I'd more likely want to
>> make a case for is tuples.  I'm having to make some changes to deal with
>> that now.
>> >
>> > The issue is that if a dict is converted to a QVariant and sent to QML,
>> any tuples in the dict hierarchy aren't getting converted properly since
>> PyQt is leaving them as `PyQt_PyObject`, which QML obviously has no clue
>> what to do with.  Right now I'm trying to determine the best way to deal
>> with this... might require recursively searching such dicts for tuples and
>> converting to lists prior to shipping to QML as a `QVariant`.  If PyQt
>> converted tuples into `QVariantList` there would no need for this.
>> >
>> > Is there a reason tuples don't get translated to QVariantList, just
>> like lists do? Immutability concerns, maybe?
>> >
>> > Also, fwiw, python `bytes` could also potentially translate to
>> `QByteArray`.  Never used that (I'm fairly new to Qt), but it seems
>> equivalent at least. It also isn't in the Qt->QML translation table [1], so
>> is of less interest.
>> The reason for both is that I want conversions to be symmetrical. I'm not
>> sure why I want that, other than it feels right. In any event any sort of
>> change would break compatibility.
>> Phil
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170203/ac7b9b27/attachment.html>

More information about the PyQt mailing list