QML :
TableView {
model: TableModel {}
}
main.cpp
qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
TableModel.h
QVector<QVector<QString>> m_Model;
TableModel.cpp
// Here is where data is getting set
bool TableModel::setData(const QModelIndex &indexPos, const QVariant &value, int role)
{
if(data(indexPos, role) == value)
return false;
QString key = m_Model.at(indexPos.row()).at(indexPos.column()-1);
qDebug() << "KEY:" << key;
m_Model.replace(indexPos.row(),{key, value});
qDebug() << "Model Data Changed!!!" << m_Model;
QModelIndex start = index(1,0);
emit dataChanged(start, indexPos, {role});
return true;
}
void changeModel() {
setData(index(1,1), "abc");
}
It is a table with two columns , a key value pair kind and the data change wil be triggered from cpp function changeModel() . Currently I was changing just the second row (1st row after header ) 2nd column value.
So In the Output of qDebug() << "Model data Changed!!!" , I am seeing the new model, but UI is not getting updated.