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.5 Fixes: QTBUG-110266 Change-Id: I32337b801aaabf9b821a97ddc15ad78747b5e6a2 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> (cherry picked from commit 9d8473cdf63537dee65e9c235249b4e4901baa1a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 7378c709f527749493bc15e66a566e1bdfc09fd3)
This commit is contained in:
parent
d19037271c
commit
acfe26b167
@ -131,6 +131,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
|
|||||||
const int id = point.id();
|
const int id = point.id();
|
||||||
switch (point.state()) {
|
switch (point.state()) {
|
||||||
case QEventPoint::Pressed:
|
case QEventPoint::Pressed:
|
||||||
|
case QEventPoint::Stationary:
|
||||||
{
|
{
|
||||||
// find the point, move it
|
// find the point, move it
|
||||||
const auto mappedPoints = m_fingerPointMapping.values();
|
const auto mappedPoints = m_fingerPointMapping.values();
|
||||||
@ -155,7 +156,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (activePoint != -1) {
|
if (activePoint != -1) {
|
||||||
m_fingerPointMapping.insert(point.id(), activePoint);
|
m_fingerPointMapping.insert(id, activePoint);
|
||||||
movePoint(activePoint, point.position());
|
movePoint(activePoint, point.position());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,8 +165,10 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
|
|||||||
{
|
{
|
||||||
// move the point and release
|
// move the point and release
|
||||||
const auto it = m_fingerPointMapping.constFind(id);
|
const auto it = m_fingerPointMapping.constFind(id);
|
||||||
movePoint(it.value(), point.position());
|
if (it != m_fingerPointMapping.constEnd()) {
|
||||||
m_fingerPointMapping.erase(it);
|
movePoint(it.value(), point.position());
|
||||||
|
m_fingerPointMapping.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEventPoint::Updated:
|
case QEventPoint::Updated:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user