PDA

View Full Version : Table View not Updating after adding a new Row



satish.joshi
26th June 2019, 14:32
Hey Folks !

Hope you all are doing well.

I have been through a lot of similar links regarding the question but yet i didn't found any perfect solution regarding that. Here's my code :



// Called this in constructor
model = new QStandardItemModel(0,0,this);

// this is the logic of showing the view for Table View
tableView = new QTableView(this);
tableView->setModel(model);
tableView->verticalHeader()->setVisible(false);
tableView->verticalHeader()->setDefaultSectionSize(10);

for(int i = 0; i < clusterNames.length(); i++) {
QStandardItem *clusterName_i = new QStandardItem(clusterNames[i]);
QStandardItem *clusterIP_i = new QStandardItem(clusterIPs[i]);

model->setItem(i, 0, clusterName_i);
model->setItem(i, 1, clusterIP_i);
}

tableView->viewport()->update();


Logic/Explanation : The logic which i am doing behind this functionality as i populate a QDialog on a button and the data which i insert on the opened Dialog which is of different class. After adding the values i close that dialog and noticed that Tree & Table View aren't updating automatically but when i close that window and reopened it i saw it with updated values.

If anyone have suggestions or the solution that would be a great help for me.

Thanks In Advance

anda_skoa
29th June 2019, 15:38
The view should update automatically if the model changes.

Maybe check if you are updating a different model than the one you are showing.