Solved How to save current index of ComboBox for supported map types
-
I try to save index of ComboBox for choosing supported map types of Open Street Map. When opening the app again, the last chosen map index should be displayed.
Qt.labs.settings
didn't work as the example below: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] } } } } } }
Is it possible to save the current index of ComboBox for maps?
-
@edip hi,
After some manipulations i figured out that Settings works correctly but currentIndex of the combobox is resetted after the model change.So do like this
Settings{ id:mycomboSettings property int maptype } ... ComboBox { onModelChanged: currentIndex = mycomboSettings.maptype Component.onDestruction: mycomboSettings.maptype = currentIndex }
just make sure you provide application name, organization and domain. See here
-
Thank you @LeLev I found a solution before but your solution is much better.