diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-09-08 14:41:42 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-24 07:54:29 +0000 |
commit | 3195b44e1c9678584c05ed823aab2eb32518d868 (patch) | |
tree | 7c13d0ee0b6f9074841862e160d19d744daeda58 /src/qml/qml/qqmlpropertyvalidator.cpp | |
parent | b101be9be64b6cc82dc357da0faeffbaab771b8f (diff) |
Allow more options for creating value types from JS objects
We allow value types to be created
1. by calling Q_INVOKABLE constructors
2. by setting their values from properties of a JS object
Both have to be opted into by setting a class info. If opted into, these
options override the existing methods. When a a type can be created by
setting its properties, that implies you can also initialize it using an
invokable constructor. However, when given a JS object, the properties
method is used.
We keep this internal and undocumented for now. As the last try (the
create(QJSValue) methods and QJSValue ctors) was not that stellar, let's
first wait a bit and see if we're getting it right this time around.
Fixes: QTBUG-106480
Change-Id: I767230924afcba032d501846cc3263dad57b7bf0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertyvalidator.cpp')
-rw-r--r-- | src/qml/qml/qqmlpropertyvalidator.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlpropertyvalidator.cpp b/src/qml/qml/qqmlpropertyvalidator.cpp index c16efc7031..c6783842dc 100644 --- a/src/qml/qml/qqmlpropertyvalidator.cpp +++ b/src/qml/qml/qqmlpropertyvalidator.cpp @@ -568,10 +568,10 @@ QQmlError QQmlPropertyValidator::validateLiteralBinding( default: return QString(); } }; - QVariant result; + QVariant result(property->propType()); if (!QQmlValueTypeProvider::createValueType( - property->propType(), - compilationUnit->bindingValueAsString(binding), result)) { + compilationUnit->bindingValueAsString(binding), + result.metaType(), result.data())) { return warnOrError(tr("Invalid property assignment: %1 expected") .arg(typeName())); } @@ -618,6 +618,8 @@ QQmlError QQmlPropertyValidator::validateLiteralBinding( } else if (property->isQObject() && bindingType == QV4::CompiledData::Binding::Type_Null) { break; + } else if (QQmlMetaType::qmlType(property->propType()).canConstructValueType()) { + break; } return warnOrError(tr("Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(property->propType().name()))); |