[PyQt] PyQt5 NULL QVariant

Matthias Kuhn matthias at opengis.ch
Thu Apr 21 15:58:03 BST 2016



On 04/21/2016 04:49 PM, Phil Thompson wrote:
> On 21 Apr 2016, at 3:46 pm, Matthias Kuhn <matthias at opengis.ch> wrote:
>> Hi Phil,
>>
>> On 04/21/2016 04:22 PM, Phil Thompson wrote:
>>> On 18 Apr 2016, at 1:27 pm, Matthias Kuhn <matthias at opengis.ch> wrote:
>>>> Hi,
>>>>
>>>> I am currently updating QGIS to PyQt5 (and Qt5 and Python3). Since this update, NULL QVariant strings are converted to empty strings '' and all numbers to 0 when converted from C++ to python objects.
>>>>
>>>> The documentation is not very verbose on this topic:
>>>>
>>>> PyQt5 does not support the QPyNullVariant class as it is no longer needed.
>>>> http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qvariant.html
>>>>
>>>> sip.enableautoconversion() which is mentioned on the same doc page probably does the job of preserving the semantics but at the same time sacrifices all the advantages of PyQt4's v2 API.
>>> The only disadvantage is having to explicitly call the value() method.
>> For newly written code that shouldn't matter.
>> The problem is, we have a huge ecosystem of plugins for which I prefer
>> to make the migration path as easy as possible.
>> Big parts of the API can be converted from PyQt4 (with SIP API v2) to
>> PyQt5 automatically. I fear that this will not be possible for this
>> change because the migration tool lacks the required data type information.
>>
>> I think the SIP API v2 of PyQt4 had a pretty good handling of python
>> representation for QVariants. Is there a big disatvantage that I don't see?
> Only the disadvantages I point out in the docs.

Which I think are properly addressed by introducing the
sip.enableautoconversion() function to allow turning autoconversion off.
But I struggle to see why this requires breaking compatiblity with SIP
API V2 if autoconversion is turned on.

Matthias


More information about the PyQt mailing list