Reputation: 36101
I have a virtual table view implementation with the following model:
class MyModel: public QAbstractListModel
{
int columnCount (const QModelIndex & parent = QModelIndex() ) const { return 2; }
int rowCount (const QModelIndex & parent = QModelIndex() ) const { return count; }
QModelIndex parent (const QModelIndex & index ) const { return QModelIndex(); }
QModelIndex index (int row, int column, const QModelIndex & parent = QModelIndex() ) const { return createIndex(row, column); }
QVariant data(const QModelIndex & index, int role) const
{
int col = index.column();
int row = index.row();
if (role == Qt::DecorationRole && col == 0)
{
return getIcon(row); // icons in the first column
}
else if (role == Qt::DisplayRole && col == 1)
{
return getText(row); // text in the second column
}
else
{
return QVariant();
}
}
void update()
{
getNewText();
getNewIcons();
emit dataChanged((index(0,0)), index(count-1,1));
}
}
After creating the table view and assigning the model for the first time, everything works fine: I get, say, 10 items in the table view.
But then I update the model, and now it has 12 items. Only first 10 of them are displayed. It looks like it cached the value of 10 and doesn't want to update it.
How can I fix that?
Upvotes: 0
Views: 139
Reputation: 36101
I solved it by calling beginRemoveRows
, endRemoveRows
, beginInsertRows
, endInsertRows
in the update
method
Upvotes: 1