diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-12-03 17:12:31 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-12-06 13:49:55 +0100 |
commit | 43dfcd1d1a03b4243b45ddfc367b93f07df8e84b (patch) | |
tree | 65d171cff2655c1c5e06f5ea70605d757bddefeb /tools/repc/repcodegenerator.cpp | |
parent | 7d889c517b6d1d30f2e504d2726fe814e2e06306 (diff) |
Fix metatype registration of signal-slot params of type QList/QMap/QHash
When declaring signals/slots that take QList/QMap/QHash parameters, we
register metatypes for them. However, we don't always register metatypes
for the parameter types of those containers. In particular, if a
parameter is declared as a POD type in a separate .rep file, metatype
registration for it is skipped.
Fixed the code generation for metatype registration for signal-slot
parameters of type QList/QMap/QHash to also register metatypes for the
contained types if required.
Pick-to: 6.2
Fixes: QTBUG-97704
Change-Id: Ic81895815c380e841c04f2d1400fc2c2cf0e3814
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'tools/repc/repcodegenerator.cpp')
-rw-r--r-- | tools/repc/repcodegenerator.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp index 175ac43..e3b9ad3 100644 --- a/tools/repc/repcodegenerator.cpp +++ b/tools/repc/repcodegenerator.cpp @@ -205,6 +205,21 @@ void RepCodeGenerator::generate(Mode mode, QString fileName) pendingMetaTypes << function.returnType; for (const ASTDeclaration &decl : function.params) { classMetaTypes << decl.type; + + // Collect types packaged by Qt containers, to register their metatypes if needed + QRegularExpression re( + QStringLiteral("(QList|QMap|QHash)<\\s*([\\w]+)\\s*(,\\s*([\\w]+))?\\s*>")); + QRegularExpressionMatch m = re.match(decl.type); + if (m.hasMatch()) { + if (auto captured = m.captured(2); + !captured.isNull() && !metaTypes.contains(captured)) { + classMetaTypes << captured; + } + if (auto captured = m.captured(4); + !captured.isNull() && !metaTypes.contains(captured)) { + classMetaTypes << captured; + } + } } }; for (const ASTFunction &function : astClass.signalsList) |