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.
--
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development