Queue Overflow
Queue Overflow

Reputation: 364

Adding and deleting items in custom model for QTableView

How better to realize adding and deleting items in a custom model for QTableView, which are working via MVC?

  1. By adding custom functions to model: add() and delete(...)?

  2. Just implement function update() and add directly elements in list attached with this QTableView.

Upvotes: 0

Views: 294

Answers (1)

BBRodriguez
BBRodriguez

Reputation: 326

I'd say it depends on the nature of your model:

If your model is holding the data to be shown itself, providing custom methods like add(const Data &data) and remove() is a common solution - just be sure to call beginInsertRows/endInsertRows and beginRemoveRows/endRemoveRows inside those methods.

If you directly access the data storage (List/Map/Whatever), it should be sufficient to just call insertRow/removeRow after adding new data.

Upvotes: 2

Related Questions