diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-03 08:37:16 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-03 09:42:12 +0200 |
commit | d73497f136fbfad5d367e5af429adb7d38af6dfe (patch) | |
tree | e808df1ba96b836e27d7ea8831da21a24bb4d712 /tests/auto/qml/qqmlcomponent | |
parent | 6dffa5400fd056e3862a2f8905362679c1bb6be7 (diff) |
QQmlComponent: Check for existence of engine
Avoid a crash when setData or create are
called after a user mistakenly used the internal constructor of
QQmlComponent which does not take an engine.
Fixes: QTBUG-55407
Change-Id: Ia4295d1b044723efce1a95607349561d4f1640da
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent')
-rw-r--r-- | tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 7c7c7d3bd0..a872cece96 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -121,6 +121,7 @@ private slots: void setNonExistentInitialProperty(); void relativeUrl_data(); void relativeUrl(); + void setDataNoEngineNoSegfault(); private: QQmlEngine engine; @@ -654,6 +655,17 @@ void tst_qqmlcomponent::relativeUrl() QVERIFY2(!component.isError(), qPrintable(component.errorString())); } +void tst_qqmlcomponent::setDataNoEngineNoSegfault() +{ + QQmlEngine eng; + QQmlComponent comp; + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling setData"); + comp.setData("import QtQuick 1.0; QtObject { }", QUrl("")); + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Must provide an engine before calling create"); + auto c = comp.create(); + QVERIFY(!c); +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" |