summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-04 09:56:43 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-09-04 13:33:57 (GMT)
commitf7be6402e089aefd445a5ab98912ff5aea511cea (patch)
treeb7bd2b10c84bdb08e24f2269cc21cc53a4562e7a /tests/auto/qgraphicsitem
parent7d41759f87db72ff9b9ff1d8ce017f466440f2ef (diff)
downloadQt-f7be6402e089aefd445a5ab98912ff5aea511cea.zip
Qt-f7be6402e089aefd445a5ab98912ff5aea511cea.tar.gz
Qt-f7be6402e089aefd445a5ab98912ff5aea511cea.tar.bz2
Fix crashes when moving descendents during destruction.
This fix prevents crashes in QGraphicsItem caused by calls to pure virtual functions as an item tries to access its dying parent. This happens when an item is moved by an ancestor during this ancestor's destructor. Autotests included. Reviewed-by: bnilsen
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 408decc..77c2d45 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -292,6 +292,7 @@ private slots:
void activate();
void setActivePanelOnInactiveScene();
void activationOnShowHide();
+ void moveWhileDeleting();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -8103,5 +8104,64 @@ void tst_QGraphicsItem::activationOnShowHide()
QVERIFY(otherItem->isActive());
}
+class MoveWhileDying : public QGraphicsRectItem
+{
+public:
+ MoveWhileDying(QGraphicsItem *parent = 0)
+ : QGraphicsRectItem(parent)
+ { }
+ ~MoveWhileDying()
+ {
+ foreach (QGraphicsItem *c, childItems()) {
+ foreach (QGraphicsItem *cc, c->childItems()) {
+ cc->moveBy(10, 10);
+ }
+ c->moveBy(10, 10);
+ }
+ if (QGraphicsItem *p = parentItem()) { p->moveBy(10, 10); }
+ }
+};
+
+void tst_QGraphicsItem::moveWhileDeleting()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ MoveWhileDying *silly = new MoveWhileDying(rect);
+ QGraphicsRectItem *child = new QGraphicsRectItem(silly);
+ scene.addItem(rect);
+ delete rect; // don't crash!
+
+ rect = new QGraphicsRectItem;
+ silly = new MoveWhileDying(rect);
+ child = new QGraphicsRectItem(silly);
+
+ QGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(125);
+
+ delete rect;
+
+ rect = new QGraphicsRectItem;
+ rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
+ silly = new MoveWhileDying(rect);
+ child = new QGraphicsRectItem(silly);
+
+ QTest::qWait(125);
+
+ delete rect;
+
+ rect = new MoveWhileDying;
+ rect->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
+ child = new QGraphicsRectItem(rect);
+ silly = new MoveWhileDying(child);
+
+ QTest::qWait(125);
+
+ delete rect;
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"