diff options
| author | Phil Thompson <phil@riverbankcomputing.com> | 2024-10-23 16:28:27 +0100 |
|---|---|---|
| committer | Phil Thompson <phil@riverbankcomputing.com> | 2024-10-29 20:04:58 +0000 |
| commit | 5624060865e3ccd3c487f10355cb740b7322f93c (patch) | |
| tree | d97badaf1be663c7db65526546588ac8ba6b8133 /src/corelib/kernel/qmetaobject.cpp | |
| parent | 1558811a8485f6dcc51a50a2bba0846091ca8bf6 (diff) | |
Fix QFlag properties built by QMetaObjectBuilder
When Q_PROPERTY is used to define a property with type (for example)
Qt::Alignment the name of the type stored in the meta-object is
"Qt::Alignment".
When QMetaObjectBuilder.addProperty() is used it will instead use the
name of the meta-type (ie. "QFlags<Qt::AlignmentFlag>") which it has
obtained from QMetaType::fromName("Qt::Alignment").name().
In the QMetaProperty ctor it tries to resolve the QMetaEnum for the
property and uses the internal parse_scope() to extract the scope and
qualified key from the name. However it does not handle template names
and so fails with dynamically created properties.
This change to parse_scope() removes the "QFlags<>" so that the
template type can then be parsed.
Another solution would be for addProperty() to always use the type name
it was given rather than use QMetaType::fromName(). That has the
advantage that the layout of the dynamic meta-object would match that
generated by moc.
Pick-to: 6.8
Change-Id: Iac9e2db2f134029709158b4e500286922396501d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
| -rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 7229bb2b66d..21f67c6d332 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -174,6 +174,8 @@ static auto parse_scope(QByteArrayView qualifiedKey) noexcept std::optional<QByteArrayView> scope; QByteArrayView key; }; + if (qualifiedKey.startsWith("QFlags<") && qualifiedKey.endsWith('>')) + qualifiedKey.slice(7, qualifiedKey.length() - 8); const auto scopePos = qualifiedKey.lastIndexOf("::"_L1); if (scopePos < 0) return R{std::nullopt, qualifiedKey}; |
