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.
Qt Code:
  1. void ReadersRoom::doPaidColumn()
  2. {
  3. model->insertColumn(5);
  4. model->setHeaderData(5,Qt::Horizontal,trUtf8("Paid"));
  5. QString s = "BLA";
  6.  
  7. for(int i = 0; i < model->rowCount(); ++i)
  8. {
  9. QModelIndex index = model->index(i,5);
  10. if(index.isValid()) // index is valid.
  11. model->setData(index,s); // returns TRUE.
  12. QString test = model->index(i,5).data().toString(); // STRING IS EMPTY!
  13. }
  14. }
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?