The QVariant type of the Qt Framework offers comparison operators <, <=, >, >=
, but they work unexpected on signed/unsigned integer arguments mismatch:
QVariant(-1) < QVariant(0u) yields false
QVariant(0u) > QVariant(-1) yields false
Does anybody know if this is a bug, or is this intended? Do this operators always return false on singed/unsigned mismatch?
Btw, I'm using Qt 5.6
QVariant(-1) < QVariant(0u)
will call built-in comparators of int
and unsigned int
. Basically, (int(-1) < uint(0)) == false
(and here it is explained why).
If you want different behavior, convert values before comparison explicitly with toInt() or similar methods:
QVariant(-1).toInt() < QVariant(0u).toInt() == true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With