on xenial help sign in
TouchEventSequenceWrapper: item might get deleted when touch sequence is committed (LP: #1607686)
aefab3fDaniel d'Andrada
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.cpp+8−3
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -26,9 +26,14 @@ TouchEventSequenceWrapper::TouchEventSequenceWrapper(QTest::QTouchEventSequence
26
26
27void TouchEventSequenceWrapper::commit(bool processEvents)
27void TouchEventSequenceWrapper::commit(bool processEvents)
28{
28{
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+
29 m_eventSequence.commit(processEvents);
33 m_eventSequence.commit(processEvents);
34+
30− if (m_item->window()) {
35+ if (window) {
31− QQuickWindowPrivate *wp = QQuickWindowPrivate::get(m_item->window());
36+ QQuickWindowPrivate *wp = QQuickWindowPrivate::get(window);
32 wp->flushDelayedTouchEvent();
37 wp->flushDelayedTouchEvent();
33 }
38 }
34}
39}
tests/utils/modules/Unity/Test/TouchEventSequenceWrapper.h+4−2
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,8 @@
21#include <QtTest/QTest>
21#include <QtTest/QTest>
22#include <QtQml/qqml.h>
22#include <QtQml/qqml.h>
23
23
24+#include <QPointer>
25+
24class QQuickItem;
26class QQuickItem;
25
27
26class TouchEventSequenceWrapper : public QObject
28class TouchEventSequenceWrapper : public QObject
@@ -37,7 +39,7 @@ public:
37
39
38private:
40private:
39 QTest::QTouchEventSequence m_eventSequence;
41 QTest::QTouchEventSequence m_eventSequence;
40− QQuickItem *m_item;
42+ QPointer<QQuickItem> m_item;
41};
43};
42
44
43QML_DECLARE_TYPE(TouchEventSequenceWrapper)
45QML_DECLARE_TYPE(TouchEventSequenceWrapper)