我尝试保存 ComboBox 的索引以选择支持的 Open Street Map 地图类型。再次打开应用程序时,应显示最后选择的地图索引。Qt.labs.settings
没有像下面的例子那样工作:
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtLocation 5.12
import QtPositioning 5.12
import Qt.labs.settings 1.0
ApplicationWindow{
id: root
width: 500
height: 500
visible: true
Settings{
id:mycombo
property alias maptype: selectmap.currentIndex
}
Flickable {
height: parent.height
width: parent.width
clip: true
contentHeight: Math.max(mapColumn.implicitHeight, height)
Column{
anchors.horizontalCenter: parent.horizontalCenter
id:mapColumn
spacing: 5
anchors.fill : parent
Row{
anchors.horizontalCenter: parent.horizontalCenter
spacing:25
Rectangle{
width:mapColumn.width
height:mapColumn.height-80
Map {
id:map
anchors.fill: parent
plugin: Plugin {
name: "osm"
}
}
}
}
Column{
id: combos
spacing: 10
width: parent.width
anchors.verticalCenter: root.verticalCenter
Row{
anchors.horizontalCenter: parent.horizontalCenter
spacing:1
Label{ text:"Map Type: "; height: selectmap.height; verticalAlignment: Text.AlignVCenter; }
// Map Types
ComboBox {
id: selectmap
width: 200
model:map.supportedMapTypes
textRole:"description"
onCurrentIndexChanged: map.activeMapType = map.supportedMapTypes[currentIndex]
}
}
}
}
}
}
是否可以为地图保存 ComboBox 的当前索引?