From dfcc156a75f32f1147e95ce06e4262c102ee858e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 17 May 2010 16:17:57 +0200 Subject: Add a test in QObject. Testing that slot from destroyed class are not called --- tests/auto/qobject/tst_qobject.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index d2307ee..4b926e4 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -135,7 +135,7 @@ private slots: void disconnectByMetaMethod(); void disconnectNotSignalMetaMethod(); void autoConnectionBehavior(); - + void baseDestroyed(); protected: }; @@ -3925,5 +3925,34 @@ void tst_QObject::autoConnectionBehavior() delete receiver; } +class BaseDestroyed : public QObject +{ Q_OBJECT + QList fooList; + bool destroyed; +public: + BaseDestroyed() : destroyed(false) + { fooList << "a" << "b"; } + ~BaseDestroyed() + { + QVERIFY(!destroyed); + destroyed = true; + } + +public slots: + void slotUseList() + { + QVERIFY(!destroyed); + fooList << "c" << "d"; + } +}; + +void tst_QObject::baseDestroyed() +{ + BaseDestroyed d; + connect(&d, SIGNAL(destroyed()), &d, SLOT(slotUseList())); + //When d goes out of scope, slotUseList should not be called as the BaseDestroyed has + // already been destroyed while ~QObject emit destroyed +} + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" -- cgit v0.12