diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-04-25 15:21:19 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-04-26 13:51:55 +0000 |
commit | dbbbbe569da0aa3900a17ca22bd2be2708fb76f7 (patch) | |
tree | df811b9177ff6c6ebbfb6b15a7bf51f872595395 | |
parent | 3a349ea9229eae7e3e189e92e3124b169fe4f447 (diff) |
Allow creation of variants from non-singleton QQmlTypeWrappers
I don't see any reason why this should be prohibited.
Change-Id: I4a54c55eff4b9151691d0587627efad4a06485f1
Fixes: QTBUG-74815
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml | 15 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 15 |
3 files changed, 31 insertions, 2 deletions
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 246de04316..24c5aecc00 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -97,9 +97,8 @@ QObject* QQmlTypeWrapper::singletonObject() const QVariant QQmlTypeWrapper::toVariant() const { - // Only Singleton type wrappers can be converted to a variant. if (!isSingleton()) - return QVariant(); + return QVariant::fromValue<QObject *>(d()->object); QQmlEngine *e = engine()->qmlEngine(); QQmlType::SingletonInstanceInfo *siinfo = d()->type().singletonInstanceInfo(); diff --git a/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml b/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml new file mode 100644 index 0000000000..8a1535ff50 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/typeWrapperToVariant.qml @@ -0,0 +1,15 @@ +import QtQml 2.0 + +QtObject { + id: root + + property QtObject target: QtObject { + Component.onCompleted: { + root.connections.target = root.target.Component + } + } + + property Connections connections: Connections { + ignoreUnknownSignals: true + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 85dddbcb54..87468c329c 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -301,6 +301,8 @@ private slots: void polymorphicFunctionLookup(); void anchorsToParentInPropertyChanges(); + void typeWrapperToVariant(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -5085,6 +5087,19 @@ void tst_qqmllanguage::anchorsToParentInPropertyChanges() QTRY_COMPARE(o->property("edgeWidth").toInt(), 200); } +void tst_qqmllanguage::typeWrapperToVariant() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("typeWrapperToVariant.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + QObject *connections = qvariant_cast<QObject *>(o->property("connections")); + QVERIFY(connections); + QObject *target = qvariant_cast<QObject *>(connections->property("target")); + QVERIFY(target); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |