diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-14 14:06:06 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-16 08:19:56 +0200 |
commit | 03196c9a0f1635ce78cf53addb6b688108f66fae (patch) | |
tree | 8f7d484419d80cfcb1a70bf98763ca43041dc41f /tests | |
parent | 383854f482a34cef14f918c2a3172522249ef542 (diff) |
Check for invalid context in QQmlContextPrivate::dropDestroyedQObject
If the context is invalid we won't be able to look up the object by name
anymore. In that case there is nothing to do.
Fixes: QTBUG-78326
Change-Id: I011ccb6b02a84725c1d5eae24b494516ae2d5fee
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index d9cb6673df..6754f22049 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -895,16 +895,27 @@ void tst_qqmlcontext::contextObjectHierarchy() void tst_qqmlcontext::destroyContextProperty() { - QQmlEngine engine; - QQmlContext context(&engine); - + QScopedPointer<QQmlContext> context; + QScopedPointer<QObject> objectThatOutlivesEngine(new QObject); { - QObject object; - context.setContextProperty(QLatin1String("a"), &object); - QCOMPARE(qvariant_cast<QObject *>(context.contextProperty(QLatin1String("a"))), &object); + QQmlEngine engine; + context.reset(new QQmlContext(&engine)); + + { + QObject object; + context->setContextProperty(QLatin1String("a"), &object); + QCOMPARE(qvariant_cast<QObject *>(context->contextProperty(QLatin1String("a"))), &object); + } + + QCOMPARE(qvariant_cast<QObject *>(context->contextProperty(QLatin1String("a"))), nullptr); + context->setContextProperty(QLatin1String("b"), objectThatOutlivesEngine.data()); } - QCOMPARE(qvariant_cast<QObject *>(context.contextProperty(QLatin1String("a"))), nullptr); + // dropDestroyedObject() should not crash, even if the engine is gone. + objectThatOutlivesEngine.reset(); + + // We're not allowed to call context->contextProperty("b") anymore. + // TODO: Or are we? } QTEST_MAIN(tst_qqmlcontext) |