Update QAbstractTableModel?
I made use of QAbstractTableModel to show data retrieved through QNetworkAccessManager in a QTableView, it works well, the only issue is that if the data is changed the model doesn't "refresh" until I click on the tableview or scroll through the table.
header:
Code:
Q_OBJECT
public:
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
) const;
void setLista(QList<QString> lista);
private:
QList<QString> listaCli;
};
source:
Code:
}
int ModelLClienti
::rowCount(const QModelIndex &parent
) const{ Q_UNUSED(parent);
return listaCli.size()-1;
}
int ModelLClienti
::columnCount(const QModelIndex &parent
) const{ Q_UNUSED(parent);
return 2;
}
if (!index.isValid())
if (index.row() >= listaCli.size() || index.row() < 0)
if (role == Qt::DisplayRole) {
l=listaCli.at(index.row()).split(',');
if(index.column()==0)
return l[0];
if (index.column() == 1)
return l[1].toUpper();
}
}
QVariant ModelLClienti
::headerData(int section, Qt
::Orientation orientation,
int role
) const{ if (role != Qt::DisplayRole)
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("clientId");
case 1:
return tr("Client");
default:
}
}
}
void ModelLClienti::setLista(QList<QString> lista){
listaCli=lista;
}
I need to change the data inside the model and afterwards, show in the tableview.
Re: Update QAbstractTableModel?
When you change data in the model, you have to emit dataChanged() signal for the index range that gets changed.
Re: Update QAbstractTableModel?