From f43cb31ba00a431c6d0a0b17750483a72ae03bb0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 23 Nov 2019 12:28:07 +0100 Subject: Deprecate QVariant::operator< and related operators Since the operator does not have a total order, it is kind of pointless, and this is going to be removed in Qt6 Change-Id: I754be059726bf30993550a2d753f8b865f2d4a5f Reviewed-by: Lars Knoll Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira Reviewed-by: Allan Sandfeld Jensen --- src/corelib/kernel/qvariant.cpp | 14 ++++++++++++++ src/corelib/kernel/qvariant.h | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 762a761026..d1eb463514 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -3829,6 +3829,7 @@ bool QVariant::convert(const int type, void *ptr) const /*! \fn bool QVariant::operator<(const QVariant &v) const + \obsolete Compares this QVariant with \a v and returns \c true if this is less than \a v. @@ -3838,10 +3839,15 @@ bool QVariant::convert(const int type, void *ptr) const \warning To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators(). + + This operator is deprecated as it cannot establish a total order required + for most use of this operator, which is the reason you cannot use QVariant + as the key of a QMap. */ /*! \fn bool QVariant::operator<=(const QVariant &v) const + \obsolete Compares this QVariant with \a v and returns \c true if this is less or equal than \a v. @@ -3851,10 +3857,13 @@ bool QVariant::convert(const int type, void *ptr) const \warning To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators(). + + This operator is deprecated as it cannot establish a total order. */ /*! \fn bool QVariant::operator>(const QVariant &v) const + \obsolete Compares this QVariant with \a v and returns \c true if this is larger than \a v. @@ -3864,10 +3873,13 @@ bool QVariant::convert(const int type, void *ptr) const \warning To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators(). + + This operator is deprecated as it cannot establish a total order. */ /*! \fn bool QVariant::operator>=(const QVariant &v) const + \obsolete Compares this QVariant with \a v and returns \c true if this is larger or equal than \a v. @@ -3877,6 +3889,8 @@ bool QVariant::convert(const int type, void *ptr) const \warning To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators(). + + This operator is deprecated as it cannot establish a total order. */ static bool qIsNumericType(uint tp) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 86c7414704..6e27c9bf1f 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -463,14 +463,16 @@ class Q_CORE_EXPORT QVariant { return cmp(v); } inline bool operator!=(const QVariant &v) const { return !cmp(v); } - inline bool operator<(const QVariant &v) const +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED inline bool operator<(const QVariant &v) const { return compare(v) < 0; } - inline bool operator<=(const QVariant &v) const + QT_DEPRECATED inline bool operator<=(const QVariant &v) const { return compare(v) <= 0; } - inline bool operator>(const QVariant &v) const + QT_DEPRECATED inline bool operator>(const QVariant &v) const { return compare(v) > 0; } - inline bool operator>=(const QVariant &v) const + QT_DEPRECATED inline bool operator>=(const QVariant &v) const { return compare(v) >= 0; } +#endif protected: friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); -- cgit v1.2.3