[Development] QVariant comparison in Qt6
thiago.macieira at intel.com
Wed Sep 23 23:15:03 CEST 2020
On Wednesday, 23 September 2020 13:24:24 PDT Milian Wolff wrote:
> > QAbstractItemModelPrivate::isVariantLessThan returns false for BOTH
> > isVariantLessThan(1, "hello") == false
> > isVariantLessThan("hello", 1) == false
> Right, sorry - I missed the part where you say "a few of the above are
> strings, the others are numbers". Mixed variant types within a single column
> is I believe a super rare case in models.
I explicitly did not mark the ones that were strings with quotes because they
aren't displayed in a model. If you are mixing, then you want consistent order
somehow and the string sorting is a good first approximation.
If you're not mixing, then QVariant's upcoming comparison operator suffices.
> So from my side: as long as there's an equivalent to comparing two QVariants
> with matching types, e.g. via a public
> QAbstractItemModelPrivate::isVariantLessThan equivalent which can then be
> used in proxy models etc., then I'm fine.
It's just QVariant::compare and QMetaType::compare.
> Please just make sure there are no string conversions or similar required
> for that common case. That was all I wanted to point our (after
> misunderstanding your example above).
Just note how QVariant(-1) > QVariant(0U), just like -1 > 0U in C++.
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel DPG Cloud Engineering
More information about the Development