diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-05-30 10:25:31 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-05 13:27:53 +0000 |
commit | 6d1317e11a8a85f23190df02ae0c69f9e4420b0e (patch) | |
tree | f10ec56ffcefaeff9f4bb03c408aace2b40d8272 /src/qml/qml/qqml.cpp | |
parent | b4ce8051af0110e3a081ec83d1c8ff953243e07c (diff) |
Allow anonymous value types to be constructed
Only anonymous object types are necessarily uncreatable. You don't need
a name in order to construct or populate a value type. Since we can now
construct QSize, QRect, and QPoint, the engine will try to construct
them from the 'F' variants where applicable. Allow this.
Pick-to: 6.5 6.6
Change-Id: I568b93c58d3184d9ac37bf0a542c0e50dd37d8de
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqml.cpp')
-rw-r--r-- | src/qml/qml/qqml.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp index ca9c1d8e52..bb740962f6 100644 --- a/src/qml/qml/qqml.cpp +++ b/src/qml/qml/qqml.cpp @@ -494,7 +494,8 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data) const char *elementName = (type.structVersion > 1 && type.forceAnonymous) ? nullptr : classElementName(type.classInfoMetaObject); - const bool creatable = (elementName != nullptr) + const bool isValueType = !(type.typeId.flags() & QMetaType::PointerToQObject); + const bool creatable = (elementName != nullptr || isValueType) && boolClassInfo(type.classInfoMetaObject, "QML.Creatable", true); QString noCreateReason; @@ -505,7 +506,7 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data) classInfo(type.classInfoMetaObject, "QML.UncreatableReason")); if (noCreateReason.isEmpty()) noCreateReason = QLatin1String("Type cannot be created in QML."); - } else if (!(type.typeId.flags() & QMetaType::PointerToQObject)) { + } else if (isValueType) { const char *method = classInfo(type.classInfoMetaObject, "QML.CreationMethod"); if (qstrcmp(method, "structured") == 0) creationMethod = ValueTypeCreationMethod::Structured; |