[Development] QVariant::operator< deprecation fallout

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Sun Nov 22 18:09:39 CET 2020


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20201122/31338a3f/attachment.bin>


More information about the Development mailing list