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

Thiago Macieira thiago.macieira at intel.com
Sat Oct 5 02:50:25 CEST 2024


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.

-- 
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/4a91a6cb/attachment.bin>


More information about the Development mailing list