aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-01-18 14:32:00 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-01-18 14:58:30 +0100
commite98b48f55cdb57a369513100f82d7c1df99c1243 (patch)
tree327a296abcced1c8bb137eef652c6373ad46cf98
parent1fa352f0e0a62d0b445e9a2a01953f8afca29858 (diff)
QQmlComponentPrivate::setInitialProperties: Do not silently swallow exceptions
Instead, log them with qmlWarning. Change-Id: Icde7397085841a84aca8a81c716d552c4cd4485a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/qml/qqmlcomponent.cpp4
-rw-r--r--tests/auto/quick/qquickloader/data/Component.qml5
-rw-r--r--tests/auto/quick/qquickloader/data/initialPropertyTriggerException.qml12
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp7
4 files changed, 25 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index f35c3011d3..d1aa2a09db 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -1387,13 +1387,13 @@ void QQmlComponentPrivate::setInitialProperties(QV4::ExecutionEngine *engine, QV
}
}
if (engine->hasException || !object) {
- engine->hasException = false;
+ qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
continue;
}
name = engine->newString(properties.last());
object->put(name, val);
if (engine->hasException) {
- engine->hasException = false;
+ qmlWarning(createdComponent, engine->catchExceptionAsQmlError());
continue;
} else if (isTopLevelProperty) {
auto prop = removePropertyFromRequired(createdComponent, name->toQString(), requiredProperties);
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);