From 1a0c2fb5bdaed175c9d9472b0658f93214572d4d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 Jul 2019 13:21:41 +0200 Subject: When setting a QObject as context property reset it when it's destroyed Fixes: QTBUG-76346 Change-Id: Ie21f831a775489f0f2ac2e296136ed4932f5154f Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/auto/qml/qqmlcontext') diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index cb4bee0d3a..d9cb6673df 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -71,6 +71,7 @@ private slots: void outerContextObject(); void contextObjectHierarchy(); + void destroyContextProperty(); private: QQmlEngine engine; @@ -892,6 +893,20 @@ void tst_qqmlcontext::contextObjectHierarchy() }); } +void tst_qqmlcontext::destroyContextProperty() +{ + QQmlEngine engine; + QQmlContext context(&engine); + + { + QObject object; + context.setContextProperty(QLatin1String("a"), &object); + QCOMPARE(qvariant_cast(context.contextProperty(QLatin1String("a"))), &object); + } + + QCOMPARE(qvariant_cast(context.contextProperty(QLatin1String("a"))), nullptr); +} + QTEST_MAIN(tst_qqmlcontext) #include "tst_qqmlcontext.moc" -- cgit v1.2.3