PDA

View Full Version : Data from model not inserted in QTableView



schmimona
4th August 2011, 10:24
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:



Clothoid *temp = new Clothoid();
temp->setStartPoint(p1);
temp->setEndPoint(p2);

clothoids.append(temp);

scene->addItem(temp);

model.setColumnCount(3);
model.setRowCount(clothoids.size());

QModelIndex index = model.index(clothoids.size(), 1, QModelIndex());
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:



QList < Clothoid *> clothoids;


The signal is connected to the slot in my main window:



ui->setupUi(this);
SpinBoxDelegate delegate;
ui->clothoidTable->setItemDelegate(&delegate);

connect(ui->graphicsView, SIGNAL(clothoidAdded(QStandardItemModel*)), ui->clothoidTable, SLOT(onClothoidAdded(QStandardItemModel*)));


where the slot is:



void TableViewList::onClothoidAdded(QStandardItemModel *model)
{
setModel(model);
}


What am I doing wrong?

Santosh Reddy
10th August 2011, 05:16
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())