[Development] QVariant comparison in Qt6

Milian Wolff mail at milianw.de
Wed Sep 23 15:59:16 CEST 2020

On Freitag, 18. September 2020 17:06:20 CEST Thiago Macieira wrote:
> On Friday, 18 September 2020 01:59:50 PDT Albert Astals Cid via Development
> wrote:
> > We have a few generic item models and proxy models that implement sorting,
> > they did so by using operator< of QVariant.
> > 
> > I want a way to be able to do the same in Qt6 in a way that ideally
> > doesn't
> > involve having to copy the QAbstractItemModelPrivate::isVariantLessThan
> > code.
> Perform an unconditional conversion to string and sort that.

For large models of numerical data, this will completely nuke the performance. 
Sure, QVariant-construction of integral data isn't free, but it's going to be 
miles ahead of creating tons of temporary string representations.

> In a model, where you're likely to *display* the element, this is probably
> the right thing to do, as you don't want to explain to your users why your
> list shows items like
> 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.

> > 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.

Milian Wolff
mail at milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200923/92172e44/attachment.sig>

More information about the Development mailing list