[Development] QVariant comparison in Qt6

Thiago Macieira thiago.macieira at intel.com
Wed Sep 23 21:12:52 CEST 2020


On Wednesday, 23 September 2020 06:59:16 PDT Milian Wolff wrote:
> > 1
> > 10
> > 11
> > 2
> > 3
> > 21
> > 
> > A few of the above are strings and the others are numbers. It should
> > always
> > lexicographically sort or use numeric/natural sorting.
> 
> This wouldn't be an issue if you sort by the integral values instead.

And how do you sort these variants:
 1
 "hello"
 "!"

if you convert to integer, the string becomes 0, so it sorts first. If you 
convert the integer to string, "1" sorts before "hello". Note that 
QAbstractItemModelPrivate::isVariantLessThan returns false for BOTH orders:

 isVariantLessThan(1, "hello") == false
 isVariantLessThan("hello", 1) == false

> > > Maybe making QAbstractItemModelPrivate::isVariantLessThan public and
> > > clearly defining what it was would be good enough (i mean if it is good
> > > enough for QAbstractItemModel it could be enough for most of the other
> > > implementations).
> > 
> > That's a good idea.
> 
> Agreed.

And fix the case above.

Which in my mind involves converting to string if the two types aren't equal 
or numeric.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Development mailing list