diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-17 17:08:30 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-18 09:15:09 +0200 |
commit | 3d2ff1931f9e7c139bb7a4c9490b2cb595d1e7bf (patch) | |
tree | 1d4f45ccf2f60131e9714efc898092a8c73e6909 /src/qml/qml/qqmlengine.cpp | |
parent | e2be7ff1656406ba0cd0fa304c9ad8ae13bf9382 (diff) |
Lower severity of nullptr error handling for qmlRegisterSingleton
Instead of aborting the execution directly, print a critical warning
message and handle the value gracefully as undefined in QML.
Change-Id: I8e508ba7fef7c61d9c5a5e13837c4a4cb2ed8486
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlengine.cpp')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 00d2a6b502..9388df5617 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2478,17 +2478,20 @@ QJSValue QQmlEnginePrivate::singletonInstance<QJSValue>(const QQmlType &type) } else if (siinfo->qobjectCallback) { QObject *o = siinfo->qobjectCallback(q, q); if (!o) { - qFatal("qmlRegisterSingletonType(): \"%s\" is not available because the callback function returns a null pointer.", - qPrintable(QString::fromUtf8(type.typeName()))); + QQmlError error; + error.setMessageType(QtMsgType::QtCriticalMsg); + error.setDescription(QString::asprintf("qmlRegisterSingletonType(): \"%s\" is not available because the callback function returns a null pointer.", + qPrintable(QString::fromUtf8(type.typeName())))); + warning(error); + } else { + // if this object can use a property cache, create it now + QQmlData::ensurePropertyCache(q, o); } - // if this object can use a property cache, create it now - QQmlData::ensurePropertyCache(q, o); // even though the object is defined in C++, qmlContext(obj) and qmlEngine(obj) // should behave identically to QML singleton types. q->setContextForObject(o, new QQmlContext(q->rootContext(), q)); value = q->newQObject(o); singletonInstances.insert(type, value); - } else if (!siinfo->url.isEmpty()) { QQmlComponent component(q, siinfo->url, QQmlComponent::PreferSynchronous); QObject *o = component.beginCreate(q->rootContext()); |