From d392d3b22c94f86fea50f26284bc9ac8b35f6851 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 7 Oct 2024 15:13:38 +0200 Subject: QMetaObjectBuilder: Fix construction logic for enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to put metatypes in the correct place; this is especially vital starting with Qt 6.9, given that we need it to query it to figure out whether we have a 64bit value or not. As a drive-by, replace some ugly casting when constructing the meta-type array with a call to QMetaType::iface. Pick-to: 6.8 Change-Id: I4b1f42f974e9f7a21f6aa4c87c3f8919f6965d6e Reviewed-by: MÃ¥rten Nordheim --- src/corelib/kernel/qmetaobjectbuilder.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp') diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 9d3d3266b2a..96b25bd3722 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1253,8 +1253,8 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, // Output the methods in the class. Q_ASSERT(!buf || dataIndex == pmeta->methodData); - // + 1 for metatype of this metaobject - int parameterMetaTypesIndex = int(d->properties.size()) + 1; + // property count + enum count + 1 for metatype of this metaobject + int parameterMetaTypesIndex = int(d->properties.size()) + int(d->enumerators.size()) + 1; for (const auto &method : d->methods) { [[maybe_unused]] int name = strings.enter(method.name()); int argc = method.parameterCount(); @@ -1418,12 +1418,19 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, } ALIGN(size, QtPrivate::QMetaTypeInterface *); - auto types = reinterpret_cast(buf + size); + auto types = reinterpret_cast(buf + size); if constexpr (mode == Construct) { meta->d.metaTypes = types; for (const auto &prop : d->properties) { QMetaType mt = prop.metaType; - *types = reinterpret_cast(mt); + *types = mt.iface(); + types++; + } + // add metatypes for enumerators + for (const auto &enumerator: d->enumerators) { + QMetaType mt = enumerator.metaType; + mt.registerType(); + *types = mt.iface(); types++; } // add metatype interface for this metaobject - must be null @@ -1436,14 +1443,14 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, types++; for (const auto ¶meterType: method.parameterTypes()) { QMetaType mt = QMetaType::fromName(parameterType); - *types = reinterpret_cast(mt); + *types = mt.iface(); types++; } } for (const auto &constructor : d->constructors) { for (const auto ¶meterType : constructor.parameterTypes()) { QMetaType mt = QMetaType::fromName(parameterType); - *types = reinterpret_cast(mt); + *types = mt.iface(); types++; } } -- cgit v1.2.3