From 2c82f4f8b61e8d7c22a979ef7ca3ea0465da278d Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Mon, 11 Jan 2021 13:07:37 +0100 Subject: qqmlengine: Fix crash when encountering bad singletons Previously errors occurring when parsing QML singletons would just be ignored resulting in a crash. The errors are now properly printed and the execution is aborted in time. Fixes: QTBUG-85932 Change-Id: I61cef5f97546ce2e0753bc46c548838a21b1f506 Reviewed-by: Fabian Kosmale --- src/qml/qml/qqmlengine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/qml/qml/qqmlengine.cpp') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index ef9fec56fb..5a20b93c2c 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2391,6 +2391,12 @@ QJSValue QQmlEnginePrivate::singletonInstance(const QQmlType &type) singletonInstances.convertAndInsert(v4engine(), type, &value); } else if (!siinfo->url.isEmpty()) { QQmlComponent component(q, siinfo->url, QQmlComponent::PreferSynchronous); + if (component.isError()) { + warning(component.errors()); + v4engine()->throwError(QLatin1String("Due to the preceding error(s), Singleton \"%1\" could not be loaded.").arg(QString::fromUtf8(type.typeName()))); + + return QJSValue(QJSValue::UndefinedValue); + } QObject *o = component.beginCreate(q->rootContext()); value = q->newQObject(o); singletonInstances.convertAndInsert(v4engine(), type, &value); -- cgit v1.2.3