c++qt5qvariantqt5.15

How to compare QVariant values in Qt 5.15?


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?


Solution

  • Unfortunately it seems we are supposed to ignore the deprecation warning. Qt6 introduced QVariant::compare but there is no equivalent in Qt5.15

    Some solutions were discussed on Qt dev mailing list but the corresponding patch got stale AFAIK