Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.1
-
None
Description
when using a based enum as a property, negative values are not converted properly.
when the base type is a type smaller than int (ex. int8 or int16)
for example
enum class EnumType : std::int8_t { Undefined = -1, SomeValue, SomeOtherValue, }
returning EnumType::Undefined to the property, it will be converted to 255 in qml.
because the value will be transferred via void* and reinterpret_cast.
a possible fix would be to change the moc compiler to generate a static_cast to int before transfering the value into the QVariant:
// some_moc.cpp // in void Type::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) // ... else if (_c == QMetaObject::ReadProperty) { Q_ASSERT(staticMetaObject.cast(_o)); auto *_t = static_cast<Type*>(_o); (void)_t; void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QObject**>(_v) = _t->GetSomeObj(); break; case 1: *reinterpret_cast< QObject**>(_v) = _t->GetOtherObj(); break; // case 2: *reinterpret_cast< Namespace::EnumType*>(_v) = _t->GetEnumValue(); break; case 2: *reinterpret_cast< int*>(_v) = static_cast<int>(_t->GetEnumValue()); break; case 3: *reinterpret_cast< bool*>(_v) = _t->GetSomeBool(); break; case 4: *reinterpret_cast< bool*>(_v) = _t->GetSomeBool(); break; // same here case 5: *reinterpret_cast< Namespace::EnumType2*>(_v) = _t->GetEnumValue2(); break; default: break; } } // ...
Attachments
Issue Links
- is covered by
-
QTBUG-112180 Properly support enums with underlying type != int
-
- Closed
-
Gerrit Reviews
For Gerrit Dashboard: QTBUG-98869 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
390287,3 | WIP: Avoid messy casting in moc generated code | dev | qt/qtbase | Status: NEW | -2 | 0 |