[Development] QVariant comparison in Qt6

Lars Knoll lars.knoll at qt.io
Fri Sep 18 10:22:16 CEST 2020



On 18 Sep 2020, at 09:12, Albert Astals Cid via Development <development at qt-project.org<mailto:development at qt-project.org>> 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".

The problem with the old comparisons was that it was rather random what compared to true and what compared to false. A bit like the much hated equality operator in JavaScript.

We’ve basically now said, that (with some exceptions for pointers of related types and numerical types) that those will not compare equal.

Is the official Qt position that we should all "copy&paste"
QAbstractItemModelPrivate::isVariantLessThan into our item model classes that
need sorting?

Sorting and equality are two different things. QVariant has never supported a lessThan operator.

Cheers,
Lars


Cheers,
 Albert

--
Albert Astals Cid | albert.astals.cid at kdab.com<mailto:albert.astals.cid at kdab.com> | Senior Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt, C++ and OpenGL Experts

_______________________________________________
Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>
https://lists.qt-project.org/listinfo/development

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200918/22866af7/attachment-0001.html>


More information about the Development mailing list