PDA

View Full Version : Error Modifiying a record of a QSqlTableModel



qlands
26th July 2011, 08:43
Hi,

I have a custom function inside a reimplementation of QSqlTableModel that intents to change a field value after the insertion. I insert the new record with:



QSqlRecord newRecord;
newRecord = mymodel->record();
newRecord.setValue("CURRCODE","TestValue");
mymodel->insertRecord(-1,newRecord);
mymodel->updateNewRecord(); //Custom function


Inside the model, the custom function updateNewRecord has:


qDebug() << "Previous Value: " << record(this->rowCount()-1).value("CURRCODE").toString(); //Prints "TestValue"
record(this->rowCount()-1).setValue("CURRCODE","Newvalue"); //Setting a new value
qDebug() << "New Value: " << record(this->rowCount()-1).value(codeColumn).toString(); //Prints "TestValue"!!!


The problem is that after setting the value with setValue()I still have the old value ("TestValue")!!!

Any idea why?

Thanks,
Carlos.

mcosta
26th July 2011, 18:41
QSqlQueryModel::record returns a copy of the record, so setValue on line 2 doesn't modify the record in the model

qlands
28th July 2011, 10:41
Yep... That was it!

Thanks.
Carlos.