diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2019-11-23 12:28:07 +0100 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2019-12-05 08:28:28 +0100 |
commit | f43cb31ba00a431c6d0a0b17750483a72ae03bb0 (patch) | |
tree | 47ae48edf280db7b481e24ef1f60c0760f80c349 | |
parent | de6520805abafbc6f898b3fec043e5d85827dfd0 (diff) |
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 <lars.knoll@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 14 | ||||
-rw-r--r-- | 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 &); |