Data from model not inserted in QTableView
I am trying to insert some data in a TableView from a model but I am doing something wrong because the data is not inserted. The table is updated with the columns and rows though.
So I have a GraphicsView where I am drawing some custom GraphicsItems. Each time a new Item is added to the scene the model is supposed to get updated and send a signal to my TableView to insert the data in it as well.
Here I update the model when the new item is added:
Code:
Clothoid *temp = new Clothoid();
temp->setStartPoint(p1);
temp->setEndPoint(p2);
clothoids.append(temp);
scene->addItem(temp);
model.setColumnCount(3);
model.setRowCount(clothoids.size());
model.setData(index, clothoids.last()->startCurvature);
index
= model.
index(clothoids.
size(),
2,
QModelIndex());
model.setData(index, clothoids.last()->endCurvature);
index
= model.
index(clothoids.
size(),
3,
QModelIndex());
model.setData(index, clothoids.last()->clothoidLength);
emit clothoidAdded(&model);
Clothoids being a list of my custom graphicsItems:
Code:
QList < Clothoid
*> clothoids;
The signal is connected to the slot in my main window:
Code:
ui->setupUi(this);
SpinBoxDelegate delegate;
ui->clothoidTable->setItemDelegate(&delegate);
where the slot is:
Code:
{
setModel(model);
}
What am I doing wrong?
Re: Data from model not inserted in QTableView
What is model? did you implement it, are the index item editable, is editable flag set.
moreover column index should be 0,1,2 (not 1,2,3), and row index should be clothoids.size() - 1 (not clothoids.size())