Hello everyone.
I want to insert a new column in a model, then fill it up with data.
The problem below is the simplified one: The model already contains 5 column from a database, filled with data.
All it want to do is insert a column, and fill each new index with the string "BLA".
The model is a QSqlTableModel.
void ReadersRoom::doPaidColumn()
{
model->insertColumn(5);
model->setHeaderData(5,Qt::Horizontal,trUtf8("Paid"));
for(int i = 0; i < model->rowCount(); ++i)
{
if(index.isValid()) // index is valid.
model->setData(index,s); // returns TRUE.
QString test
= model
->index
(i,
5).
data().
toString();
// STRING IS EMPTY! }
}
void ReadersRoom::doPaidColumn()
{
model->insertColumn(5);
model->setHeaderData(5,Qt::Horizontal,trUtf8("Paid"));
QString s = "BLA";
for(int i = 0; i < model->rowCount(); ++i)
{
QModelIndex index = model->index(i,5);
if(index.isValid()) // index is valid.
model->setData(index,s); // returns TRUE.
QString test = model->index(i,5).data().toString(); // STRING IS EMPTY!
}
}
To copy to clipboard, switch view to plain text mode
The result(on a tableview):
the new column is there and it contains nothing.
If I try to rewrite the 4th column with this method it works fine. But the setData won't put any data in the newly added column.
What am I doing wrong?
Bookmarks