Hi,

I think we should at least _somehow_ deprecate operator<; but I'm not sure if 
it should be a special deprecation macro, or a special one. Regarding point 4: 
Unfortunately, it's not that easy: If userType is actually a built-in type, 
then QMetaType::hasRegisteredComparators returns false, and QMetaType compare 
will not work. I'm afraid that in this case you would actually have to call the 
deprecated operator< [1]; unless we provide a replacement functionality in 
5.15.3.

[1] Though operator< would still behave different for floating point values 
than QVariant::compare, as the former does a fuzzy compare for floating point 
values, and the latter and a strict comparison.

Fabian

--
Fabian Kosmale
Software Engineer

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin
fabian.kosm...@qt.io
+49 1638686070
http://qt.io


Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

--

________________________________________
Von: Development <development-boun...@qt-project.org> im Auftrag von Giuseppe 
D'Angelo via Development <development@qt-project.org>
Gesendet: Sonntag, 22. November 2020 18:09
An: development@qt-project.org
Betreff: [Development] QVariant::operator< deprecation fallout

QVariant::operator< has been deprecated in 5.15 because its broken
semantics, unable to establish a strict weak order (as expected by
"operator<". cf. VALUE.16 of QUIP-19).

The problem with this deprecation is that it doesn't offer a
replacement. Users that are still on Qt 5.15 and want to get rid of
deprecation warnings won't be able to get rid of this one. (Whether they
do this in order to upgrade to Qt 6 or just to keep their codebase clean
is irrelevant).

Only Qt 6 introduced a replacement (QVariant::compare()).


== Solutions ==

1) Un-deprecate operator<. The operator has been broken since forever,
we're not going to fix it anyhow, we just expect users to understand its
limitations (e.g. only use it between QVariants containing the same kind
of data, for for instance in order to sort a model's data).


2) Change the deprecation macro to another one that isn't included in
5.15 deprecations -- rather, one has to opt-in for. The opt-in is
supposed to be used only when targeting Qt 6, and not by projects which
want to stay on 5.15.

(This kind of macro could be applied to any other similar deprecation in
Qt 5.15 that doesn't have a corresponding replacement.)


3) Actually add a replacement for operator<. Possibly something that can
be mechanically ported to Q6Variant::compare via search&replace.


4) At least document how to avoid the warning, i.e. how to compare
"safely" two QVariants. Is there enough public API for this?

Thinking of

a) compare the variants' userType(), different -> uncomparable
b) check QMetaType::hasRegisteredComparators(type), false -> uncomparable
c) call QMetaType::compare(v1.data(), v2.data(), v1.userType(), result)
and return *result

This should be almost identical in Qt 6 (only step b) doesn't exist).



Opinions?
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to