summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qvariant.cpp27
-rw-r--r--src/corelib/kernel/qvariant.h2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 31c2173072..ad52921cb7 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -2329,6 +2329,33 @@ bool QVariant::equals(const QVariant &v) const
}
/*!
+ Compares the objects at \a lhs and \a rhs for ordering.
+
+ Returns an std::nullopt if comparison is not supported or the values are unordered.
+ Otherwise, returns -1, 0 or +1 according as \a lhs is less than, equal to or greater
+ than \a rhs.
+
+ If the variants contain data with a different metatype, the values are considered
+ unordered unless they are both of numeric or pointer types, where regular numeric or
+ pointer comparison rules will be used.
+
+ If both variants contain data of the same metatype, the method will use the
+ QMetaType::compare method to determine the ordering of the two variants, which can
+ also indicate that it can't establish an ordering between the two values.
+
+ \since 6.0
+ \sa QMetaType::compare(), QMetaType::isOrdered()
+*/
+std::optional<int> QVariant::compare(const QVariant &lhs, const QVariant &rhs)
+{
+ QMetaType t = lhs.d.type();
+ if (t != rhs.d.type())
+ return std::nullopt;
+ return t.compare(lhs.constData(), rhs.constData());
+}
+
+
+/*!
\fn const void *QVariant::constData() const
\fn const void* QVariant::data() const
\internal
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 83cb40a7c7..c28f841356 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -492,6 +492,8 @@ class Q_CORE_EXPORT QVariant
inline bool operator!=(const QVariant &v) const
{ return !equals(v); }
+ static std::optional<int> compare(const QVariant &lhs, const QVariant &rhs);
+
protected:
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &);
#ifndef QT_NO_DEBUG_STREAM