[PyQt] Type map for python to Qt?

Phil Thompson phil at riverbankcomputing.com
Thu Feb 2 17:12:04 GMT 2017


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


More information about the PyQt mailing list