From 2b371a50cbc1f54284fcea3834834ca58fc28fd0 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 4 Oct 2019 16:20:29 +0200 Subject: 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 Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/qml/qqmlengine/tst_qqmlengine.cpp') diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index aae42e9ebb..64f167b47e 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -1107,6 +1107,16 @@ void tst_qqmlengine::singletonInstance() SomeQObjectClass * instance = engine.singletonInstance(cppSingletonTypeId); QVERIFY(!instance); } + + { + // deleted object + auto dayfly = new QObject{}; + auto id = qmlRegisterSingletonInstance("Vanity", 1, 0, "Dayfly", dayfly); + delete dayfly; + QTest::ignoreMessage(QtMsgType::QtWarningMsg, ": The registered singleton has already been deleted. Ensure that it outlives the engine."); + QObject *instance = engine.singletonInstance(id); + QVERIFY(!instance); + } } void tst_qqmlengine::aggressiveGc() -- cgit v1.2.3