summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@trolltech.com>2009-04-14 16:05:26 (GMT)
committerAlexis Menard <alexis.menard@trolltech.com>2009-04-14 16:31:54 (GMT)
commit0bb526f8fab33a42df56c8a60c272e2cca4cc792 (patch)
tree6e621df7a192ce1fc31305aead2c1af905b38e7d /tests/auto/qgraphicsitem
parent0f6950e11389a3ddf657116a98ee8f4ec0753eb4 (diff)
downloadQt-0bb526f8fab33a42df56c8a60c272e2cca4cc792.zip
Qt-0bb526f8fab33a42df56c8a60c272e2cca4cc792.tar.gz
Qt-0bb526f8fab33a42df56c8a60c272e2cca4cc792.tar.bz2
QGraphicsItem: When an item is deleted and eventfilters installed
The problem here is that we are filling the sceneEventFilters map when we install evenfilter but we never remove the references of an item if it has been removed from the scene or deleted. The deletion can keep stale pointers into the map and a crash can happen. BT:yes Task-number:250272 Reviewed-by: bnilsen Reviewed-by: andreas
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index ad0dc97..5dd7e1e 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -4037,6 +4037,25 @@ void tst_QGraphicsItem::sceneEventFilter()
QCOMPARE(tester->filteredEventReceivers.at(6), static_cast<QGraphicsItem *>(text2));
QVERIFY(text2->hasFocus());
+
+ //Let check if the items are correctly removed from the sceneEventFilters array
+ //to avoid stale pointers.
+ QGraphicsView gv;
+ QGraphicsScene *anotherScene = new QGraphicsScene;
+ QGraphicsTextItem *ti = anotherScene->addText("This is a test #1");
+ ti->moveBy(50, 50);
+ QGraphicsTextItem *ti2 = anotherScene->addText("This is a test #2");
+ QGraphicsTextItem *ti3 = anotherScene->addText("This is a test #3");
+ gv.setScene(anotherScene);
+ gv.show();
+ QTest::qWait(250);
+ ti->installSceneEventFilter(ti2);
+ ti3->installSceneEventFilter(ti);
+ delete ti2;
+ //we souldn't crash
+ QTest::mouseMove(gv.viewport(), gv.mapFromScene(ti->scenePos()));
+ QTest::qWait(250);
+ delete ti;
}
class GeometryChanger : public QGraphicsItem