on xenial help sign in
TouchEventSequenceWrapper: item might get deleted when touch sequence is committed (LP: #1607686)

Approved by: Albert Astals Cid

commitaefab3f99896abe05aa572c7b6612aafeb142ca0 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 3 Aug 2016, 15:53 (10 years ago) parent59464a1ffde5e4
2 files changed+12−5
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.cpp+8−3 tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.h+4−2
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.cpp+8−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -26,9 +26,14 @@ TouchEventSequenceWrapper::TouchEventSequenceWrapper(QTest::QTouchEventSequence
2626
2727void TouchEventSequenceWrapper::commit(bool processEvents)
2828{
29+ // Item might be deleted as a consequence of this event sequence being handled
30+ // So store its window beforehand
31+ QQuickWindow *window = m_item->window();
32+
2933 m_eventSequence.commit(processEvents);
30− if (m_item->window()) {
31− QQuickWindowPrivate *wp = QQuickWindowPrivate::get(m_item->window());
34+
35+ if (window) {
36+ QQuickWindowPrivate *wp = QQuickWindowPrivate::get(window);
3237 wp->flushDelayedTouchEvent();
3338 }
3439}
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.h+4−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,8 @@
2121#include <QtTest/QTest>
2222#include <QtQml/qqml.h>
2323
24+#include <QPointer>
25+
2426class QQuickItem;
2527
2628class TouchEventSequenceWrapper : public QObject
@@ -37,7 +39,7 @@ public:
3739
3840private:
3941 QTest::QTouchEventSequence m_eventSequence;
40− QQuickItem *m_item;
42+ QPointer<QQuickItem> m_item;
4143};
4244
4345QML_DECLARE_TYPE(TouchEventSequenceWrapper)