Why am I getting invalid data from my QTouchPoint?
I have a QGraphicsScene with QGraphicsItems. I have reimplemented the sceneEvent function and handle multi-touch.
The problem is that randomly I get invalid values out of this section:
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
const QTouchEvent::TouchPoint &p0 = touchPoints.first();
Gives the following debug information (not all the time):
Debug: TouchUpdate: p0.scenePos(): QPointF(489.76, 160.71) :
Debug: TouchUpdate: p0.startPos(): QPointF(-8.62078e+14, 1.83351e+15)
I have no idea why startPos() should be a random 开发者_Go百科value like that. Any suggestions?
Are you blindly casting events or using a switch-case statement as below ?
bool MyItem::sceneEvent(QEvent *event)
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
//Remember to accept the event too
event->accept();
break;
}
}
精彩评论