diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qtouchevent/tst_qtouchevent.cpp | 31 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 86aaa78..4472272 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5712,8 +5712,15 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) item->d_ptr->acceptedTouchBeginEvent = true; bool res = sendTouchBeginEvent(item, &touchEvent) && touchEvent.isAccepted(); - if (!res) + if (!res) { + // forget about these touch points, we didn't handle them + for (int i = 0; i < touchEvent.touchPoints().count(); ++i) { + const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i); + itemForTouchPointId.remove(touchPoint.id()); + sceneCurrentTouchPoints.remove(touchPoint.id()); + } ignoreSceneTouchEvent = false; + } break; } default: diff --git a/tests/auto/qtouchevent/tst_qtouchevent.cpp b/tests/auto/qtouchevent/tst_qtouchevent.cpp index 639f8e4..bb80fde 100644 --- a/tests/auto/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/qtouchevent/tst_qtouchevent.cpp @@ -193,6 +193,7 @@ private slots: void multiPointRawEventTranslationOnTouchPad(); void deleteInEventHandler(); void deleteInRawEventTranslation(); + void crashInQGraphicsSceneAfterNotHandlingTouchBegin(); }; void tst_QTouchEvent::touchDisabledByDefault() @@ -1303,6 +1304,36 @@ void tst_QTouchEvent::deleteInRawEventTranslation() qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); } +void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin() +{ + QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100); + rect->setAcceptTouchEvents(true); + + QGraphicsRectItem *mainRect = new QGraphicsRectItem(0, 0, 100, 100, rect); + mainRect->setBrush(Qt::lightGray); + + QGraphicsRectItem *button = new QGraphicsRectItem(-20, -20, 40, 40, mainRect); + button->setPos(50, 50); + button->setBrush(Qt::darkGreen); + + QGraphicsView view; + QGraphicsScene scene; + scene.addItem(rect); + scene.setSceneRect(0,0,100,100); + view.setScene(&scene); + + view.show(); + QTest::qWaitForWindowShown(&view); + + QPoint centerPos = view.mapFromScene(rect->boundingRect().center()); + // Touch the button + QTest::touchEvent(view.viewport()).press(0, centerPos); + QTest::touchEvent(view.viewport()).release(0, centerPos); + // Touch outside of the button + QTest::touchEvent(view.viewport()).press(0, view.mapFromScene(QPoint(10, 10))); + QTest::touchEvent(view.viewport()).release(0, view.mapFromScene(QPoint(10, 10))); +} + QTEST_MAIN(tst_QTouchEvent) #include "tst_qtouchevent.moc" |