From 481d70818e9bb157e9167a0a2817a7e9254a5eca Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sun, 2 Apr 2023 09:05:05 +0200 Subject: Follow up on meta object version bump in qtbase After b83de5f9a43b094bbb77b3aeea77983ea508a2b0 in qtbase, moc generates complete type information for enum types. ActiveQt declares enums from type libraries (i.e. on namespace level) also in the metaobject of each generated class (as we can't inherit the namespace meta object from each QAxObject class). But those enum types don't really exist on C++ level. So moc generates incorrectly qualified enum types. Augment the post-processing code to detect whether a type that is actually in the namespace is used as if it was in the class, and replace the qualifier. Bump the metaobject revision. Change-Id: I4d28abaa47a5fa3db70737d006b8e1becf8a51e3 Reviewed-by: Fabian Kosmale --- tools/dumpcpp/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/dumpcpp/main.cpp b/tools/dumpcpp/main.cpp index 9820a76..1b6fbeb 100644 --- a/tools/dumpcpp/main.cpp +++ b/tools/dumpcpp/main.cpp @@ -537,12 +537,13 @@ bool generateClassImpl(QTextStream &out, const QMetaObject *mo, const QByteArray bool useControlName, QString *errorString) { - Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 11, "dumpcpp should generate the same version as moc"); + Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 12, "dumpcpp should generate the same version as moc"); QByteArray qualifiedClassName; if (!nameSpace.isEmpty()) qualifiedClassName = nameSpace + "::"; qualifiedClassName += className; + const QByteArray nestedQualifier = className + "::"; QString moCode = mocCode(mo, QLatin1String(qualifiedClassName), errorString); if (moCode.isEmpty()) { @@ -567,7 +568,21 @@ bool generateClassImpl(QTextStream &out, const QMetaObject *mo, const QByteArray if (type.endsWith(u'*')) type.chop(1); type = type.trimmed(); - const auto namespaceForTypeEntry = namespaceForType.constFind(type.toUtf8()); + + // If ActiveQt thinks it's a nested type within the class, but it really is a type in the + // namespace, then we need to replace the nested type qualifier with the real namespace. + const bool isNestedType = type.startsWith(QString::fromUtf8(nestedQualifier)); + auto namespaceForTypeEntry = namespaceForType.constEnd(); + if (isNestedType) { + const QString rawType = type.mid(nestedQualifier.length()); + namespaceForTypeEntry = namespaceForType.constFind(rawType.toUtf8()); + if (namespaceForTypeEntry != namespaceForType.constEnd()) { + moCode.remove(startType, nestedQualifier.length()); + type = rawType; + } + } + if (namespaceForTypeEntry == namespaceForType.constEnd()) + namespaceForTypeEntry = namespaceForType.constFind(type.toUtf8()); if (namespaceForTypeEntry != namespaceForType.constEnd()) { const auto ns = QString::fromUtf8(namespaceForTypeEntry.value()); moCode.insert(startType, ns + QStringView(u"::")); -- cgit v1.2.1