I'm confused about what the correct way to reset or clear the data in associated with a QAbstractItemModel
?.
I'm writing an application in which the user can "start over" with a new set of data (empty, or small).
Should I be deleting the old model when the user makes this request? Or should I leave the model alone and just remove all of the rows?
Regards, Dan O
foreach (Type* t, list) delete t; list. clear(); c++
About the content of table, you can use QTableWidget::clear to clear. But the table header, you should reset or delete them. you can use takeHorizontalHeaderItem(int column) to take header item, and then to delete it.
Generally I would prefer to have the model react to changes and take the necessary actions to update it's view (indirectly ofcourse). However, programming models can be (=is) a PITA, so I would probably look through the fingers if I was reviewing code that created a new model and deleted the old one. Only do this if you are sure the user only will delete all rows. If the user may delete items from the model incrementally you're probably best off implementing removal properly in the first place...
Also, ModelTest might help you discover problems with your Qt models.
If the user is truly starting over with a new set of data, then it makes sense to me to simply delete the old model and create a new one. Simple, effective, and it matches up to what the user is doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With