Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.14
-
None
Description
QVariant has a "magic" ability to convert from int and QString towards an enumeration registered via Q_ENUM. When using a QString, there is a check in place to verify that the string is the name of an enumerator:
QVariant v("CoarseTimerXXX"); // not an enumerator bool ok = v.convert(qMetaTypeId(Qt::TimerType)); // false
The same check is not there for integers:
QVariant v(123456); // not a valid value bool ok = v.convert(qMetaTypeId(Qt::TimerType)); // TRUE (!)
I'd argue that the second should fail as well. Yes, in C++ it's legitimate and well-defined behavior store that integer value into the enumeration; but we're dealing with QVariant and a conversion, and I'd expect it to be strictier.