diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-12-12 12:25:11 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-12-15 17:30:36 +0100 |
commit | 9d8473cdf63537dee65e9c235249b4e4901baa1a (patch) | |
tree | 2dc634988e8347ce01f9062b74177c47572b79bd | |
parent | f6566dd4c6aafa60c134fa40e2c48c6706724363 (diff) |
Examples: fix touch handling in painting examples
On macOS, we don't deliver a press event for the first press on the
track pad (Qt::WA_TouchPadAcceptSingleTouchEvents is not set by default,
so Qt doesn't deliver a single-press on the track pad as a touch event -
that makes some sense or at least maintains compatibility). Because of
that, point 0 is never added to the finger-mapping hash.
When point 0 is then released, we didn't check if we found a valid
iterator for that point ID, and the example crashed.
Fix this by checking that we have a valid iterator before dereferencing,
and by handling Stationary events in the same way as pressed (add the
point to the mapping if it's not already there).
Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-110266
Change-Id: I32337b801aaabf9b821a97ddc15ad78747b5e6a2
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r-- | examples/widgets/painting/shared/hoverpoints.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 1df6f214ae..a917139613 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -127,6 +127,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) const int id = point.id(); switch (point.state()) { case QEventPoint::Pressed: + case QEventPoint::Stationary: { // find the point, move it const auto mappedPoints = m_fingerPointMapping.values(); @@ -151,7 +152,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) } } if (activePoint != -1) { - m_fingerPointMapping.insert(point.id(), activePoint); + m_fingerPointMapping.insert(id, activePoint); movePoint(activePoint, point.position()); } } @@ -160,8 +161,10 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) { // move the point and release const auto it = m_fingerPointMapping.constFind(id); - movePoint(it.value(), point.position()); - m_fingerPointMapping.erase(it); + if (it != m_fingerPointMapping.constEnd()) { + movePoint(it.value(), point.position()); + m_fingerPointMapping.erase(it); + } } break; case QEventPoint::Updated: |