Solved TabBar and model update
-
Hi,
I build a QML model (ListModel) width a submodel.
ListModel { id: modelstart ListElement { key: qsTr("Manuel"); option: [ ListElement { choice: qsTr("Délais") }, ListElement { choice: qsTr("Date") } ]} ListElement { key: qsTr("Déclencheur"); option: [ ListElement { choice: qsTr("Voies logiques") }, ListElement { choice: qsTr("Voie Analogique") }, ListElement { choice: qsTr("(OU) Voies") }, ListElement { choice: qsTr("(ET) Voies") }, ListElement { choice: qsTr("Pente Voies") } ] } ListElement { key: qsTr("Attente"); option: [ ListElement { choice: qsTr("Délais") }, ListElement { choice: qsTr("Date") } ] } ListElement { key: qsTr("Automatique"); option: [ ListElement { choice: qsTr("Délais") }, ListElement { choice: qsTr("Date") } ]} }
I use TabBar for displaying all possibilities like this:
TabBar { id: tabBar2 width: parent.width anchors.bottom: parent.bottom Repeater{ model: modelstart.get(tabBar.currentIndex).option TabButton { text: choice } } } TabBar { id: tabBar width: parent.width anchors.top: parent.top Repeater{ model:modelstart TabButton { text: key } } }
But the application crashes when I change the tabBar currentIndex. Should I avoid the model update like this way?
Thank you
-
Hi @RomanoFX,
I dont have an exact answer for your question as I too haven't explored these new controls. But I suspect there could be some problem with model change intabBar2
'sRepeater
. Whenever the current Index oftabBar
is changed the binding is re-evaluated ( can be checked usingonModelChanged
signal handler ) intabBar2
'sRepeater
and might be the source of crash.
An alternative would be to do as follows:// Inside tabBar onCurrentIndexChanged: { for(var i=0; i<tabBar2.count; i++) tabBar2.itemAt(i).text = modelstart.get(currentIndex).option.get(i).choice } //Inside tabBar2 Repeater{ model: 2 TabButton { } }
-
Hi @p3c0,
Thank you for that answer