[Development] Changed enum property behaviour in Qt v6.8

Thiago Macieira thiago.macieira at intel.com
Fri Oct 4 16:32:53 CEST 2024


On Friday 4 October 2024 05:43:38 GMT-7 Phil Thompson via Development wrote:
> For dynamically created meta-objects...
> 
> - the results were dependent on the version of Qt
> - QMetaProperty.metaType().isValid() always returned false
> - QMetaProperty.isEnumType() returned true for v6.7.1 and false for
> v6.8.0

But how was this constructed? Is it setting the QMP and QME's metatype using 
QMetaEnumBuilder::setMetaType and QMetaPropertyBuilder::setMetaType? Uh... 
there is no such function for QMPB.

> I was surprised by the result of QMetaProperty.isEnumType() for a
> moc-generated meta-object without Q_ENUM. The docs suggest this should
> be true for all enums whether or not Q_ENUM is used.

No, it needs the bit set by moc, so Q_ENUM or Q_FLAG is required. The doc may 
be misleading then ("if the property's type is an enumeration value").

> Why does QMetaProperty.metaType().isValid() always return true for
> moc-generated meta-objects and false for dynamically created
> meta-objects?

Because meta types for all properties are required since 6.0. There are no 
exceptions. Since 6.6, moc also generates the metatypes for all enums too.

QMetaObjectBuilder always generates the latest revision of the meta object, so 
all features are available... but also all requirements are mandatory. Meta 
types for all properties, enums, methods , and for gadgets the gadget itself 
must be provided.

> Is there any way to dynamically register an enum with the meta-type
> system (so that QMetaEnum.metaType().isValid() returns true)?

Sure. And registration is automatic anyway.

All you should need to do is pass the necessary QMetaType

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Principal Engineer - Intel DCAI Platform & System Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5152 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20241004/1fa11583/attachment.bin>


More information about the Development mailing list