From 5e0c3a798ab0d70be45a107661fc5f0a17322a2a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 2 Mar 2018 09:09:17 +0100 Subject: Fix calling Qt.createComponent() from QQmlEngine::evaluate() If we're run from a top-level evaluate() call from the JS engine, then let's assume that any created components are top-level components that belong to the root QML engine context. This is not quite a typical use-case, but our API allows for this and this seems like an easy and sensible solution. Task-number: QTBUG-66792 Change-Id: Ic1c9171c257e8e60c0b2c43f9194bd038744ed2d Reviewed-by: Oleg Yadrov Reviewed-by: Michael Brasser --- tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index bf964a5744..52e18011cb 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -76,6 +76,7 @@ private slots: void qmlContextProperties(); void testGCCorruption(); void testGroupedPropertyRevisions(); + void componentFromEval(); public slots: QObject *createAQObjectForOwnershipTest () @@ -885,6 +886,17 @@ void tst_qqmlengine::testGroupedPropertyRevisions() QVERIFY(!c2.errorString().isEmpty()); } +void tst_qqmlengine::componentFromEval() +{ + QQmlEngine engine; + const QUrl testUrl = testFileUrl("EmptyComponent.qml"); + QJSValue result = engine.evaluate("Qt.createComponent(\"" + testUrl.toString() + "\");"); + QPointer component(qobject_cast(result.toQObject())); + QVERIFY(!component.isNull()); + QScopedPointer item(component->create()); + QVERIFY(!item.isNull()); +} + QTEST_MAIN(tst_qqmlengine) #include "tst_qqmlengine.moc" -- cgit v1.2.3