diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2014-01-22 18:33:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-25 18:26:36 +0100 |
commit | 55b545b5926fd2ecbb54c0d7bdeba0d79b4cf656 (patch) | |
tree | b933c6044073541b32f78862ff26de8b3ca98902 | |
parent | afb5bf71c942d411d6102ce637bc7499d8ae467c (diff) |
Flickable: fix crash in delayed press handling
Task-number: QTBUG-31328
Change-Id: Ic87e9b4db09242b49f104a8f38e4e420c62db75c
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickflickable/data/pressDelayWithLoader.qml | 18 | ||||
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 18 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index 333c11cb29..ec199a5a9b 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -1234,7 +1234,7 @@ void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event) d->replayDelayedPress(); // Now send the release - if (window()->mouseGrabberItem()) { + if (window() && window()->mouseGrabberItem()) { QPointF localPos = window()->mouseGrabberItem()->mapFromScene(event->windowPos()); QScopedPointer<QMouseEvent> mouseEvent(QQuickWindowPrivate::cloneMouseEvent(event, &localPos)); window()->sendEvent(window()->mouseGrabberItem(), mouseEvent.data()); diff --git a/tests/auto/quick/qquickflickable/data/pressDelayWithLoader.qml b/tests/auto/quick/qquickflickable/data/pressDelayWithLoader.qml new file mode 100644 index 0000000000..7ef4e70c95 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/pressDelayWithLoader.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Loader { + id: loader + + width: 300 + height: 300 + + sourceComponent: Flickable { + pressDelay: 1000 + contentWidth: loader.width + contentHeight: loader.height + MouseArea { + anchors.fill: parent + onPressed: loader.sourceComponent = null + } + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 33e753df57..8ab86bf2d3 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -97,6 +97,7 @@ private slots: void stopAtBounds(); void stopAtBounds_data(); void nestedMouseAreaUsingTouch(); + void pressDelayWithLoader(); private: void flickWithTouch(QWindow *window, QTouchDevice *touchDevice, const QPoint &from, const QPoint &to); @@ -1580,6 +1581,23 @@ void tst_qquickflickable::nestedMouseAreaUsingTouch() QVERIFY(nested->y() < 100.0); } +// QTBUG-31328 +void tst_qquickflickable::pressDelayWithLoader() +{ + QScopedPointer<QQuickView> window(new QQuickView); + window->setSource(testFileUrl("pressDelayWithLoader.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window.data()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QVERIFY(window->rootObject() != 0); + + // do not crash + QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); + QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150)); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" |