aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-11-27 11:00:59 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-12-05 13:26:32 +0100
commitaaec25a798352fc222f86ab3b299384575f51dc8 (patch)
tree577a15561689e65d8288c6c9596f9a103909f58e /tests/auto
parent75b6ef710cddbf9395df35650438f0feb57ec076 (diff)
StackView: fix crash when recursively removing items
This can happen when e.g. calling clear() in Component.onDestruction in response to a pop() call. The patch fixes the crash by warning and returning early. If users really need to do this, the clear() call can be delayed: Component.onDestruction: { Qt.callLater(function() { stackView.clear(StackView.Immediate) }) } Change-Id: If3cf07495bb34b96089522f44c36976bd6c62492 Fixes: QTBUG-80353 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/controls/data/tst_stackview.qml100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml
index a9fbf874..c6515f77 100644
--- a/tests/auto/controls/data/tst_stackview.qml
+++ b/tests/auto/controls/data/tst_stackview.qml
@@ -1245,4 +1245,104 @@ TestCase {
gc()
verify(control.initialItem)
}
+
+ // Need to use this specific structure in order to reproduce the crash.
+ Component {
+ id: clearUponDestructionContainerComponent
+
+ Item {
+ id: container
+ objectName: "container"
+
+ property alias control: stackView
+ property var onDestructionCallback
+
+ property Component clearUponDestructionComponent: Component {
+ id: clearUponDestructionComponent
+
+ Item {
+ objectName: "clearUponDestructionItem"
+ Component.onDestruction: container.onDestructionCallback(stackView)
+ }
+ }
+
+ StackView {
+ id: stackView
+ initialItem: Item {
+ objectName: "initialItem"
+ }
+ }
+ }
+ }
+
+ // QTBUG-80353
+ // Tests that calling clear() in Component.onDestruction in response to that
+ // item being removed (e.g. via an earlier call to clear()) results in a warning and not a crash.
+ function test_recursiveClearClear() {
+ let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
+ { onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
+ verify(container)
+
+ let control = container.control
+ control.push(container.clearUponDestructionComponent, StackView.Immediate)
+
+ // Shouldn't crash.
+ ignoreWarning(new RegExp(".*cannot clear while already in the process of removing elements"))
+ control.clear(StackView.Immediate)
+ }
+
+ function test_recursivePopClear() {
+ let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
+ { onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
+ verify(container)
+
+ let control = container.control
+ control.push(container.clearUponDestructionComponent, StackView.Immediate)
+
+ // Pop all items except the first, removing the second item we pushed in the process.
+ // Shouldn't crash.
+ ignoreWarning(new RegExp(".*cannot clear while already in the process of removing elements"))
+ control.pop(null, StackView.Immediate)
+ }
+
+ function test_recursivePopPop() {
+ let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
+ { onDestructionCallback: function(stackView) { stackView.pop(null, StackView.Immediate) }})
+ verify(container)
+
+ let control = container.control
+ // Push an extra item so that we can call pop(null) and reproduce the conditions for the crash.
+ control.push(component, StackView.Immediate)
+ control.push(container.clearUponDestructionComponent, StackView.Immediate)
+
+ // Pop the top item, then pop down to the first item in response.
+ ignoreWarning(new RegExp(".*cannot pop while already in the process of removing elements"))
+ control.pop(StackView.Immediate)
+ }
+
+ function test_recursiveReplaceClear() {
+ let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
+ { onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
+ verify(container)
+
+ let control = container.control
+ control.push(container.clearUponDestructionComponent, StackView.Immediate)
+
+ // Replace the top item, then clear in response.
+ ignoreWarning(new RegExp(".*cannot clear while already in the process of removing elements"))
+ control.replace(component, StackView.Immediate)
+ }
+
+ function test_recursiveClearReplace() {
+ let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
+ { onDestructionCallback: function(stackView) { stackView.replace(component, StackView.Immediate) }})
+ verify(container)
+
+ let control = container.control
+ control.push(container.clearUponDestructionComponent, StackView.Immediate)
+
+ // Replace the top item, then clear in response.
+ ignoreWarning(new RegExp(".*cannot replace while already in the process of removing elements"))
+ control.clear(StackView.Immediate)
+ }
}