aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertyvalidator.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-03-20 16:04:45 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2024-03-27 00:41:52 +0100
commit332170d46a8b75ac9635d8304a47f75a501feebc (patch)
tree1e1d495b6eebd616e0ba71d0b7a40ebc209eb875 /src/qml/qml/qqmlpropertyvalidator.cpp
parent9dc056c5171a2ddae963cf45fa4fb5bd3978e674 (diff)
Engine: Handle grouped property bindings of non-registered types
It is possible to expose a type to QML which exposes a QObject (derived) property, which then gets used to create a grouped binding. The type of the property might not have been registered in QML, or it might be part of a base class which exposes the type already in another module. If that module is not imported (or does not exist at all), the property creator would so far bail out. Simply skipping the check would lead to crashes further down, as we also lack the property cache needed during object creation. However, in Qt 6, we can lift this restriction: We can retrieve the property's metatype, and from there we can fetch the metaobject. Once we have the metaobject, we can on-demand create a property-cache for it, and use that later in the object creator. One restriction we add is that the type must not have a dynamic meta-object, given that those don't lend themselves to usable propety caches (given their dynamic nature.) The early check in the property validator is adjusted accordingly. Add a quick test to verify that gadgets continue to work as before. As a drive-by, convert a few repeated QString::arg calls to a single call of the variadic overload. Task-number: QTBUG-122321 Pick-to: 6.7 Change-Id: I860af981250a70f541794b57db3764415ea172f0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertyvalidator.cpp')
-rw-r--r--src/qml/qml/qqmlpropertyvalidator.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlpropertyvalidator.cpp b/src/qml/qml/qqmlpropertyvalidator.cpp
index a49393e425..5ae3829c27 100644
--- a/src/qml/qml/qqmlpropertyvalidator.cpp
+++ b/src/qml/qml/qqmlpropertyvalidator.cpp
@@ -302,17 +302,25 @@ QVector<QQmlError> QQmlPropertyValidator::validateObject(
return recordError(
binding->location,
tr("Invalid grouped property access: Property \"%1\" with primitive type \"%2\".")
- .arg(name)
- .arg(QString::fromUtf8(type.name()))
+ .arg(name, QString::fromUtf8(type.name()))
);
}
if (!QQmlMetaType::propertyCacheForType(type)) {
- return recordError(binding->location,
- tr("Invalid grouped property access: Property \"%1\" with type \"%2\", which is not a value type")
- .arg(name)
- .arg(QString::fromUtf8(type.name()))
- );
+ auto mo = type.metaObject();
+ if (!mo) {
+ return recordError(binding->location,
+ tr("Invalid grouped property access: Property \"%1\" with type \"%2\", which is neither a value nor an object type")
+ .arg(name, QString::fromUtf8(type.name()))
+ );
+ }
+ if (QMetaObjectPrivate::get(mo)->flags & DynamicMetaObject) {
+ return recordError(binding->location,
+ QString::fromLatin1("Unsupported grouped property access: Property \"%1\" with type \"%2\" has a dynamic meta-object.")
+ .arg(name, QString::fromUtf8(type.name()))
+ );
+ }
+ // fall through, this is okay
}
}
}