[Development] QVariant comparison in Qt6

André Somers andre at familiesomers.nl
Fri Sep 18 11:00:23 CEST 2020

On 18-09-2020 09:12, Albert Astals Cid via Development wrote:
> El divendres, 18 de setembre de 2020, a les 2:54:53 CEST, Thiago Macieira va
> escriure:
>> On Thursday, 17 September 2020 16:15:47 PDT Bernhard Lindner wrote:
>>> Hi!
>>> There was a discussion about the decision to deprecate (remove?) QVariant
>>> comparison (<,>) in Qt6 completely.
>>> Has anything changed for Qt6 (especially regarding comparison of equal
>>> and/or convertible types)? Is the complete deprecation still the latest
>>> decision?
>> Yes, it's changed; no, it's not deprecation.
>> What's been removed is the conversion. Aside from the numeric types,
>> comparing two variants of different types will always result in false. If
>> you want to compare across types, convert one to the other's type or to a
>> common third type. You know what data you put in there and you should know
>> what conversions can be lossy or not.
> But i don't what data someone else put it in a QVariant.
> The fact that QAbstractItemModelPrivate::isVariantLessThan exists should be
> proof enough that you can't expect my class to know what someone else put
> inside a QVariant, i mean that's basically the defining feature of QVariant "it
> can hold random things for you".
>   Is the official Qt position that we should all "copy&paste"
> QAbstractItemModelPrivate::isVariantLessThan into our item model classes that
> need sorting?

How often do you really have items of different QVariant types in a 
single column and and role in a model?

 From what I understand, in Qt 6 you can still compare QVariants if they 
contain the same type - be that a user type or not - for both equality 
and lessThan provided the type in QVariant supports such comparisons. Right?


More information about the Development mailing list