Updating the Values in AbstractListModel in Qt
-
I am facing a problem in updating a QAbstractListmodel, i have used qml for front end and qt for back end, i have used QList as a data structure for model , i am clearing contents of QList at start and added new values to the QList, i am getting the count of the list as 0, but the view is taking both old values plus new value, Is there a way so that modified values instantly reflected in the view and old values should not be shown not shown?
-
@Sanjeev-Gudisagar
That should already be the case. I suspect you're not going to get any help without supplying your code. -
Did you write a custom model ? Are you using Qlist inside the QAbstractListmodel ? Are you inserting the content inside the list ? Are you sending the dataChanged(..) signal ? Are you calling beginInsert() and endInsert() functions before inserting ?
-
@dheerendra Yes i have used custom model, Yes i have used QList inside QAbstractListModel, Yes i am inserting content inside a list, i am not sending the dataChanged() signal, yes i have called both Insert functions before inserting.
-
Are you cleaning the contents of entire model & inserting the fresh rows or just updating few rows inside the model ?
-
@dheerendra i am updating the model with new rows
-
@dheerendra i have cleared the contents of QList, since model contains QList clearing the contents of QList should automaically update the model OR Should i have to explicitly tell model to update?
-
Did you try to reset the model ? like begineResetModel and endResetModel ?
-
@Sanjeev-Gudisagar said in Updating the Values in AbstractListModel in Qt:
should automaically update the model
How? the model has no way of knowing what happens to your QList. you need to beginRemoveRows/endRemoveRows to tell the model you are removing items from the model.
Subclassing models is a messy business, you can use QAbstractItemModelTester to help you spot common mistakes
-
@dheerendra i have used both of them its working fine, thank you