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

Fabian Kosmale fabian.kosmale at qt.io
Tue Oct 8 08:59:14 CEST 2024


Hi,

as an additional heads-up: The QMetaObjectBuilder had a bug which caused 
it to not actually store the metatypes for the enums. This should be 
fixed (in dev and then 6.8(.1)) when 
https://codereview.qt-project.org/c/qt/qtbase/+/596122 merges.

Kind regards,
Fabian

On 05.10.24 18:37, Phil Thompson via Development wrote:
> Thanks - that was extremely helpful.
> 
> On 05/10/2024 01:50, Thiago Macieira wrote:
>> On Friday 4 October 2024 07:42:39 GMT-7 Phil Thompson via Development 
>> wrote:
>>> Understood - but there seems to be no obvious way to dynamically create
>>> and register a valid QMetaType.
>>
>> What do you mean by a dynamic meta type? Are you trying to wrap some 
>> other
>> language? Because if the type exists in C++, it exists as a metatype.
>>
>> If you're trying to wrap, then create a QtPrivate::QMetaTypeInterface 
>> and fill
>> it in appropriately. See https://qt.godbolt.org/z/5EW14qz3Y for an 
>> example of
>> the metatype for an enum and https://qt.godbolt.org/z/67PPfecdE for a 
>> Q_ENUM.
>> Most of the fields are self-explanatory, but here's a decode:
>>
>> * flags = RelocatableType | IsEnumeration, maybe isUnsignedEnumeration
>> * typeId = must be set to zero by you and QMetaType will update with 
>> the ID
>> * metaObjectFn = you should fill in
>> * name = must be present and must be unique
>> * default, copy, moveCtr, dtor  = nullptr for trivial types
>> * equals, lessThan = optional but probably a good idea for enums
>> * debugStream = optional (huh, QMT is failing to extract for enums
>> * datastreams = optional but recommended
>> * legacyRegisterOp = nullptr for enums is fine
>>
>> Each of the callback functions is called with a pointer to the QMTI in
>> question so you can return different things where needed (the meta 
>> object, in
>> particular). One trick is to create your type deriving from 
>> QMetaTypeInterface
>> and add the information you need in your own members after that; in your
>> callbacks, static_cast the pointer that was passed to your type to 
>> access the
>> extra fields.

-- 
Fabian Kosmale
Manager R&D

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin
fabian.kosmale at qt.io
+49 1638686070


More information about the Development mailing list