aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqml.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2019-10-04 16:20:29 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2019-10-07 08:06:32 +0200
commit2b371a50cbc1f54284fcea3834834ca58fc28fd0 (patch)
tree156ec5ad28cbf98fac083a870e79daf0ebb49bf3 /src/qml/qml/qqml.cpp
parent138f09bd63b8070686ed8a282375dbcf3ce7674f (diff)
qmlRegisterSingletonInstance: Do not crash if instance gets deleted
Use a QPointer, so that we notice if the object has been deleted. Also ensure that in the documentation the function is in a single line, as qdoc will otherwise silently omit it. Change-Id: Idecd370d00089997cd18b3247ad2290a561b2b69 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqml.cpp')
-rw-r--r--src/qml/qml/qqml.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp
index 8a50b51b5d..5b16a3c9e2 100644
--- a/src/qml/qml/qqml.cpp
+++ b/src/qml/qml/qqml.cpp
@@ -79,6 +79,13 @@ int qmlTypeId(const char *uri, int versionMajor, int versionMinor, const char *q
// From qqmlprivate.h
QObject *QQmlPrivate::RegisterSingletonFunctor::operator()(QQmlEngine *qeng, QJSEngine *)
{
+ if (!m_object) {
+ QQmlError error;
+ error.setDescription(QLatin1String("The registered singleton has already been deleted. Ensure that it outlives the engine."));
+ QQmlEnginePrivate::get(qeng)->warning(qeng, error);
+ return nullptr;
+ }
+
if (qeng->thread() != m_object->thread()) {
QQmlError error;
error.setDescription(QLatin1String("Registered object must live in the same thread as the engine it was registered with"));