Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 593
hyde Avatar asked Oct 15 '25 23:10

hyde


1 Answers

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

like image 86
Simon Schmeißer Avatar answered Oct 18 '25 13:10

Simon Schmeißer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!