我正在尝试创建一个 SwipeView ,其中第一页具有interactive
属性false,而其他页面则启用了该属性。我要实现的效果是使主页具有指向其他页面的链接,但是其他页面只能返回主页(如iOS设置菜单)。
问题在于,在第一个更改页面之后,currentIndex
属性失去了绑定,导致 SwipeView 断开。
这是应用程序的输出:
qrc:/main.qml:10:5: QML SwipeView: Binding loop detected for property "currentIndex"
file:///home/rcc/Qt/5.12.6/gcc_64/qml/QtQuick/Controls.2/SwipeView.qml:49:18: QML ListView: Binding loop detected for property "currentIndex"
,这是默认的滑动视图应用程序(QtCreator-> New Project-> Qt Quick Application-滑动)main.qml
:
import QtQuick 2.12
import QtQuick.Controls 2.5
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Tabs")
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
interactive: false
onCurrentIndexChanged: {
if (currentIndex === 0) {
interactive = false
} else {
interactive = true
}
}
Page1Form {}
Page2Form {}
}
footer: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("Page 1")
}
TabButton {
text: qsTr("Page 2")
}
}
}
重现该错误:
有解决此问题的建议吗?
答案 0 :(得分:0)
我是still looking into this,但现在您应该可以通过延迟分配给交互式属性来解决该问题:
onCurrentIndexChanged: {
if (currentIndex === 0) {
Qt.callLater(function() { interactive = false })
} else {
Qt.callLater(function() { interactive = true })
}
}