summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qapplication.cpp
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-12-11 10:38:19 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-12-11 12:02:32 (GMT)
commit05ba6bad6c0927d22ccf026446dfdb9d85b3f03e (patch)
treea571739da8bb9f706d6623a6e72fd01367ee3fec /src/gui/kernel/qapplication.cpp
parentbafc505ea03ff423c02e0380ba6f255e160483a1 (diff)
downloadQt-05ba6bad6c0927d22ccf026446dfdb9d85b3f03e.zip
Qt-05ba6bad6c0927d22ccf026446dfdb9d85b3f03e.tar.gz
Qt-05ba6bad6c0927d22ccf026446dfdb9d85b3f03e.tar.bz2
Fix crashes when deleting QWidgets and QGraphicsItems in touch event handlers.
Use QWeakPointer to bail out early if a widget is deleted while we are delivering/propagating a TouchBegin event. In QGraphicsScene, we need to make sure that we clear the scene's active touch points for items that are removed from the scene. This allows us to detect when an item is removed during TouchBegin event delivery/propagation. Unlike QWidget, propagation continues since we use a hit-test instead of the item's hierarchy for propagation. Task-number: QTBUG-6654 Reviewed-by: bnilsen
Diffstat (limited to 'src/gui/kernel/qapplication.cpp')
-rw-r--r--src/gui/kernel/qapplication.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 9f4cd0c..8c63968 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -4092,9 +4092,15 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents);
touchEvent->setWidget(widget);
touchEvent->setAccepted(acceptTouchEvents);
+ QWeakPointer<QWidget> p = widget;
res = acceptTouchEvents && d->notify_helper(widget, touchEvent);
eventAccepted = touchEvent->isAccepted();
- widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
+ if (p.isNull()) {
+ // widget was deleted
+ widget = 0;
+ } else {
+ widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
+ }
touchEvent->spont = false;
if (res && eventAccepted) {
// the first widget to accept the TouchBegin gets an implicit grab.
@@ -4103,7 +4109,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
d->widgetForTouchPointId[touchPoint.id()] = widget;
}
break;
- } else if (widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) {
+ } else if (p.isNull() || widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) {
break;
}
QPoint offset = widget->pos();