ListView problems
-
I am working with this wizard and it is using
ListView
. The inherent problem here is that the user's selection may change the model data which in turn changes theListView
delegate components causing thecurrentIndex
to be reset to zero. Therefore, I added in some memory:///Save the last index when "next" button is clicked onClicked: { setupList.incrementCurrentIndex() currentSelectedVehicle.setConfigurationResumeStep(setupList.currentIndex) } //When model resets onModelChanged: { setupList.currentIndex = currentSelectedVehicle.lastConfigurationStep setupList.positionViewAtIndex(setupList.currentIndex, ListView.Beginning) }
this does keep everything from going backwards whenever the model changes. However, I wanted to add a feature to reduce button presses. In other words, I didn't want the user to have to click next every time they make a selection.
So, in the delegate, I created a signal called
progressWizard
:signal progressWizard
which will fire whenever the user makes a "acceptable" selection from one of the many components that could potentially be loaded. I am catching that signal in the delegate defintion:
delegate: Item { id: buffer HardwareSettingsDisplay { anchors.fill: parent title: modelData.label onProgressWizard: { setupList.incrementCurrentIndex() currentSelectedVehicle.setConfigurationResumeStep(setupList.currentIndex) } } }
as you can see it's the same logic seen in the "next" button. This works great except whenever the user makes a selection that changes the model data. When that happens I get this error:
ReferenceError: progressWizard is not defined
coming from within the delegate. Any idea what I am doing wrong here?
-
I have a tentative solution. If I add a
Connections
to the modelData inside the individual component and then toggleprogressWizard()
onValueChanged
it works. I am not sure if this is the best solution. If no one tells me otherwise here in the next few days then I will mark this as solved and move on.