[PyQt] PyQt API 2: equivalent of Null QVariant?

Phil Thompson phil at riverbankcomputing.com
Tue Dec 21 22:14:49 GMT 2010


On Tue, 21 Dec 2010 21:06:11 +0100, TP <paratribulations at free.fr> wrote:
> Phil Thompson wrote:
> 
>> The short answer is that you can't. However...
>> 
>> QVariant::isNull() typically delegates to the enclosed data's isNull()
>> method (eg. QString::isNull()). So your example for API v1 will also
work
>> for API v2.
>> 
>> It gets a bit more complicated if you are also using the QString v2 API
>> because a null QString and an empty QString are both converted to an
>> empty
>> unicode object (although None is converted to a null QString when going
>> in
>> the other direction). I chose this asymmetric behaviour because
QString()
>> creates a null QString when often what is really meant is an empty
>> QString.
> 
> Thanks for your answer.
> 
> I have checked that API2 for QVariant works by using isNull() as you
said.
> 
> But, I cannot use API2 for QString.
> 
> This means that I must stick to API1 for QString, at least.
> 
> Will API1 support be continued in the next versions of PyQt?
> Indeed, detecting NULL is for me very important.

API v1 will be supported until PyQt5 or Python v4.

Phil


More information about the PyQt mailing list