Details
-
Bug
-
Resolution: Cannot Reproduce
-
P2: Important
-
None
-
5.12.0, 5.12.1, 5.12.2, 5.12.3, 5.12.4
-
None
Description
On a project I'm working on, this situation causes an assert in QQuickStackLayout because when it tries to use `itemAt` with the current index, `itemAt` returns `nullptr`. The assertion is in `QQuickStackLayout::rearrange(const QSizeF &newSize)`.
I could not reproduce the crash with a sample project, the assert might be caused by something else. But the behavior where the currentIndex doesn't change happens in both the sample code and the project I'm working on.
import QtQuick 2.12 import QtQuick.Layouts 1.4 import QtQuick.Controls 2.4ApplicationWindow { id: mainWindow width: 640 height: 480 title: "Window #1" color: "#495567" StackLayout { id: sl anchors { top: parent.top left: parent.left right: parent.right bottom: btn.top } currentIndex: count - 1 Rectangle { id: rect1 width: 300 height: 300 color: "red" Layout.fillWidth: true Layout.fillHeight: true } Rectangle { width: 300 height: 300 color: "green" Layout.fillWidth: true Layout.fillHeight: true } Rectangle { width: 300 height: 300 color: "blue" Layout.fillWidth: true Layout.fillHeight: true } Rectangle { width: 300 height: 300 color: "pink" Layout.fillWidth: true Layout.fillHeight: true } } Text { text: "currentIndex: " + sl.currentIndex } Row { anchors { top: parent.top right: parent.right } Button { text: "<" onClicked: { sl.currentIndex-- } } Button { text: ">" onClicked: { sl.currentIndex++ } } } Button { id: btn anchors { bottom: parent.bottom horizontalCenter: parent.horizontalCenter } onClicked: { console.log("BEFORE -> currentIndex:", sl.currentIndex) sl.children[sl.currentIndex].parent = null console.log("AFTER -> currentIndex:", sl.currentIndex) } } }