summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2012-11-20 13:34:06 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-23 17:04:00 +0100
commit43619db05d55ca619dac11fdb7327b2b45507cb9 (patch)
tree189b51b67bc5c6384cc5693a3e6bba01c737d914 /tests
parent3101e48b2c9449e6634a01ceb9a2d79598dbd368 (diff)
Emit destroyed() signal before children get deleted
Make sure we always emit the destroyed() signal before we delete our children. This wasn't working correctly for QWidget based classes, as the QWidget destructor deletes all children itself. Task-number: QTBUG-24672 Change-Id: Iecdff3489196271177edfeba1c4a2c5800e255af Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index f3f63b2067..2a5e59f825 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -396,6 +396,8 @@ private slots:
void touchEventSynthesizedMouseEvent();
void styleSheetPropagation();
+
+ void destroyedSignal();
private:
bool ensureScreenSize(int width, int height);
QWidget *testWidget;
@@ -9592,6 +9594,104 @@ void tst_QWidget::styleSheetPropagation()
}
}
+class DestroyTester : public QObject
+{
+ Q_OBJECT
+public:
+ DestroyTester(QObject *parent) : QObject(parent) { parentDestroyed = 0; }
+ static int parentDestroyed;
+public slots:
+ void parentDestroyedSlot() {
+ ++parentDestroyed;
+ }
+};
+
+int DestroyTester::parentDestroyed = 0;
+
+void tst_QWidget::destroyedSignal()
+{
+ {
+ QWidget *w = new QWidget;
+ DestroyTester *t = new DestroyTester(w);
+ connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete w;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ }
+
+ {
+ QWidget *w = new QWidget;
+ DestroyTester *t = new DestroyTester(w);
+ connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ w->blockSignals(true);
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete w;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ }
+
+ {
+ QObject *o = new QWidget;
+ DestroyTester *t = new DestroyTester(o);
+ connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete o;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ }
+
+ {
+ QObject *o = new QWidget;
+ DestroyTester *t = new DestroyTester(o);
+ connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ o->blockSignals(true);
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete o;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ }
+
+ {
+ QWidget *w = new QWidget;
+ DestroyTester *t = new DestroyTester(0);
+ connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete w;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ delete t;
+ }
+
+ {
+ QWidget *w = new QWidget;
+ DestroyTester *t = new DestroyTester(0);
+ connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ w->blockSignals(true);
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete w;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ delete t;
+ }
+
+ {
+ QObject *o = new QWidget;
+ DestroyTester *t = new DestroyTester(0);
+ connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete o;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ delete t;
+ }
+
+ {
+ QObject *o = new QWidget;
+ DestroyTester *t = new DestroyTester(0);
+ connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot()));
+ o->blockSignals(true);
+ QCOMPARE(DestroyTester::parentDestroyed, 0);
+ delete o;
+ QCOMPARE(DestroyTester::parentDestroyed, 1);
+ delete t;
+ }
+
+}
+
#ifndef QTEST_NO_CURSOR
void tst_QWidget::underMouse()
{