2

Qt 5.15 has QVariant compare operators deprecated:

#if QT_DEPRECATED_SINCE(5, 15)
    QT_DEPRECATED inline bool operator<(const QVariant &v) const
    { return compare(v) < 0; }
    QT_DEPRECATED inline bool operator<=(const QVariant &v) const
    { return compare(v) <= 0; }
    QT_DEPRECATED inline bool operator>(const QVariant &v) const
    { return compare(v) > 0; }
    QT_DEPRECATED inline bool operator>=(const QVariant &v) const
    { return compare(v) >= 0; }
#endif

There is the protected compare function, as seen used above:

int compare(const QVariant &other) const;

But, as said, it is protected.

How to compare QVariant values in Qt 5.15 when using QT_DEPRECATED_SINCE(5, 15), with the same (arguably broken) semantics that were used before?

hyde
  • 60,639
  • 21
  • 115
  • 176
  • 2
    Note: The reason for deprecation is, because QVariant values may not always be comparable, and these operators have no way to return this result. This can lead to problems if QVariant is used as a key for QMap or std::map, for example. Removing these operators prevents this, which is nice from type safety point of view. – hyde Aug 23 '22 at 06:27
  • Another note: The solution in Qt6 is a new public method, static QPartialOrdering QVariant::compare(....), but that doesn't really help here. – hyde Aug 23 '22 at 06:28

0 Answers0