diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-01 14:26:44 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-21 14:38:32 +0200 |
commit | 1eed1b860534f481b89b411fc7e21a7daa22d5ee (patch) | |
tree | f5f0d2291c1dbbb4c5fd4a897fd08956c438075b /src/qml/qml/qqmlproperty.cpp | |
parent | 488a37c861a1724a935a8d7b925693a38918a71a (diff) |
Fix interface handling in bindings
If a type had a property with an interface type, we did not support the
case where the assigned binding value is convertible to the interface.
This is now fixed by adding a last new check to QQmlPrivate::write
Fixes: QTBUG-78721
Change-Id: I0b85fbfdf8561ba43610ac343001ae380287a674
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 5f57e0eca1..b6baa86bd7 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1373,8 +1373,9 @@ bool QQmlPropertyPrivate::write(QObject *object, } } if (!ok) { - // the only other option is that they are assigning a single value + // the only other options are that they are assigning a single value // to a sequence type property (eg, an int to a QList<int> property). + // or that we encountered an interface type // Note that we've already handled single-value assignment to QList<QUrl> properties. if (variantType == QVariant::Int && propertyType == qMetaTypeId<QList<int> >()) { QList<int> list; @@ -1405,6 +1406,15 @@ bool QQmlPropertyPrivate::write(QObject *object, } } + if (!ok && QQmlMetaType::isInterface(propertyType)) { + auto valueAsQObject = qvariant_cast<QObject *>(value); + if (valueAsQObject && valueAsQObject->qt_metacast(QQmlMetaType::interfaceIId(propertyType))) { + // this case can occur when object has an interface type + // and the variant contains a type implementing the interface + return property.writeProperty(object, const_cast<void *>(value.constData()), flags); + } + } + if (ok) { return property.writeProperty(object, const_cast<void *>(v.constData()), flags); } else { |