[PyQt] PyQt5 NULL QVariant

Phil Thompson phil at riverbankcomputing.com
Thu Apr 21 16:59:57 BST 2016


On 21 Apr 2016, at 3:58 pm, Matthias Kuhn <matthias at opengis.ch> wrote:
> 
> 
> 
> 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.

Maybe I'm not understanding. Apart from QPyNullVariant not being implemented (which was a hack), what has broken?

Phil


More information about the PyQt mailing list