diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-28 11:18:04 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-09-05 11:41:25 +0200 |
commit | 36478e252f0c4fff1553a611619aa32d1f79efb5 (patch) | |
tree | 9c1c36d481481a6bc9e5f203d4bf6dd5c42516fa /src/qml/qml/qqmlpropertycache.cpp | |
parent | 8742807c2f1a3937b2d05aae8490a7a8e084e514 (diff) |
QtQml: Cache correct properties for signal handlers
This exposes some invalid QML code in our tests: We shouldn't override
signals in QML and we now notice. Since banning it outright would be a
pretty drastic change in behavior, we only print a warning for now.
Coverity-Id: 416620
Change-Id: I28c6b818c4abccb830b0e6998fe840bf229bf081
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache.cpp')
-rw-r--r-- | src/qml/qml/qqmlpropertycache.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index d368433949..e99c26cec8 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -352,6 +352,18 @@ QQmlPropertyCache::copyAndAppend(const QMetaObject *metaObject, return rv; } +static QHashedString signalNameToHandlerName(const QHashedString &methodName) +{ + return QQmlSignalNames::signalNameToHandlerName(methodName); +} + +static QHashedString signalNameToHandlerName(const QHashedCStringRef &methodName) +{ + return QQmlSignalNames::signalNameToHandlerName( + QLatin1StringView{ methodName.constData(), methodName.length() }); +} + + void QQmlPropertyCache::append(const QMetaObject *metaObject, QTypeRevision typeVersion, QQmlPropertyData::Flags propertyFlags, @@ -440,40 +452,29 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, QQmlPropertyData *old = nullptr; - if (utf8) { - QHashedString methodName(QString::fromUtf8(rawName, cptr - rawName)); + const auto doSetNamedProperty = [&](const auto &methodName) { if (StringCache::mapped_type *it = stringCache.value(methodName)) { if (handleOverride(methodName, data, (old = it->second)) == InvalidOverride) - continue; + return; } - setNamedProperty(methodName, ii, data); - if (data->isSignal()) { - QHashedString on(QQmlSignalNames::signalNameToHandlerName(methodName)); - setNamedProperty(on, ii, sigdata); - ++signalHandlerIndex; - } - } else { - QHashedCStringRef methodName(rawName, cptr - rawName); - if (StringCache::mapped_type *it = stringCache.value(methodName)) { - if (handleOverride(methodName, data, (old = it->second)) == InvalidOverride) - continue; - } setNamedProperty(methodName, ii, data); if (data->isSignal()) { - QHashedString on(QQmlSignalNames::signalNameToHandlerName( - QLatin1StringView{ methodName.constData(), methodName.length() })); - setNamedProperty(on, ii, data); + + // TODO: Remove this once we can. Signals should not be overridable. + if (!utf8) + data->m_flags.setIsOverridableSignal(true); + + setNamedProperty(signalNameToHandlerName(methodName), ii, sigdata); ++signalHandlerIndex; } - } + }; - if (old) { - // We only overload methods in the same class, exactly like C++ - if (old->isFunction() && old->coreIndex() >= methodOffset) - data->m_flags.setIsOverload(true); - } + if (utf8) + doSetNamedProperty(QHashedString(QString::fromUtf8(rawName, cptr - rawName))); + else + doSetNamedProperty(QHashedCStringRef(rawName, cptr - rawName)); } int propCount = metaObject->propertyCount(); |