From e98b48f55cdb57a369513100f82d7c1df99c1243 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 18 Jan 2021 14:32:00 +0100 Subject: QQmlComponentPrivate::setInitialProperties: Do not silently swallow exceptions Instead, log them with qmlWarning. Change-Id: Icde7397085841a84aca8a81c716d552c4cd4485a Reviewed-by: Ulf Hermann --- tests/auto/quick/qquickloader/data/Component.qml | 5 +++++ .../qquickloader/data/initialPropertyTriggerException.qml | 12 ++++++++++++ tests/auto/quick/qquickloader/tst_qquickloader.cpp | 7 ++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/auto/quick/qquickloader/data/Component.qml create mode 100644 tests/auto/quick/qquickloader/data/initialPropertyTriggerException.qml (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquickloader/data/Component.qml b/tests/auto/quick/qquickloader/data/Component.qml new file mode 100644 index 0000000000..8a9318a0de --- /dev/null +++ b/tests/auto/quick/qquickloader/data/Component.qml @@ -0,0 +1,5 @@ +import QtQuick 2.15 + +Item { + property int i +} diff --git a/tests/auto/quick/qquickloader/data/initialPropertyTriggerException.qml b/tests/auto/quick/qquickloader/data/initialPropertyTriggerException.qml new file mode 100644 index 0000000000..457a6a4e26 --- /dev/null +++ b/tests/auto/quick/qquickloader/data/initialPropertyTriggerException.qml @@ -0,0 +1,12 @@ +import QtQuick 2.15 + +Item { + id: root + Loader { + id: myloader + } + function f() {} + Component.onCompleted: { + myloader.setSource("Component.qml", {"i": root.f}); + } +} diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 698f410f9f..fcc6d0914d 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -706,6 +706,11 @@ void tst_QQuickLoader::initialPropertyValues_data() << QStringList() << (QStringList() << "i") << (QVariantList() << 12); + + QTest::newRow("initial property errors get reported") << testFileUrl("initialPropertyTriggerException.qml") + << (QStringList() << "^.*:11: Error: Cannot assign JavaScript function to int") + << QStringList() + << QVariantList(); } void tst_QQuickLoader::initialPropertyValues() @@ -718,7 +723,7 @@ void tst_QQuickLoader::initialPropertyValues() ThreadedTestHTTPServer server(dataDirectory()); foreach (const QString &warning, expectedWarnings) - QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(warning.toLatin1().constData())); QQmlEngine engine; QQmlComponent component(&engine, qmlFile); -- cgit v1.2.3