[Qt-interest] Saving changes in a QSqlRecord
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Sat Dec 12 02:37:23 CET 2009
Once you get the record, its completely isolated from the model...
You can change it all you want, and the model has no idea.
The step you are missing,
tableModel->setRecord( idx, record ); // or something like that
then do the submitAll
-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Timothy Reaves
Sent: Friday, December 11, 2009 4:50 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Saving changes in a QSqlRecord
I'm trying to saved the changes I'm making to a QSqlRecord using
submitAll(), but the changes do not get to the database. Am I not doing
something I'm supposed to? Here is the code I use:
QSqlRecord record = tableModel->record(selectedRowIndex);
if (!record.isEmpty()) {
qDebug() << "Record: " << record;
record.setValue(4, state == Qt::Checked);
qDebug() << "Record: " << record;
}else {
qDebug() << "Empty record returned!";
}
if (!tableModel->submitAll()) {
qWarning() << "Error saving data. Error is: " <<
tableModel->lastError();
}
qDebug() << "Record: " << record;
The qDebug() statements print out the correct data, so I know
that I have the correct record, and the record reflects the change.
Any help appreciated!
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list