diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-04 16:20:29 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-07 08:06:32 +0200 |
commit | 2b371a50cbc1f54284fcea3834834ca58fc28fd0 (patch) | |
tree | 156ec5ad28cbf98fac083a870e79daf0ebb49bf3 /tests/auto/qml/qqmlengine | |
parent | 138f09bd63b8070686ed8a282375dbcf3ce7674f (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 'tests/auto/qml/qqmlengine')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
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<SomeQObjectClass*>(cppSingletonTypeId); QVERIFY(!instance); } + + { + // deleted object + auto dayfly = new QObject{}; + auto id = qmlRegisterSingletonInstance("Vanity", 1, 0, "Dayfly", dayfly); + delete dayfly; + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "<Unknown File>: The registered singleton has already been deleted. Ensure that it outlives the engine."); + QObject *instance = engine.singletonInstance<QObject*>(id); + QVERIFY(!instance); + } } void tst_qqmlengine::aggressiveGc() |