I suspect I am thinking about QSqlTableModels in an overly simplistic fashion. (I'm new to both C++ and QT.)
I have a QSqlTableModel, filled with data from an imported CSV file, that I want to write to the database (SQLite).
Before it gets finally written, I give the user a chance to look over what will be written. Then, when they hit IMPORT, I timestamp the records in the tablemodel (the import date is row 5 in the table), and submit them to the database.
Only, my timestamp doesn't work. The records save OK, but without the timestamp.
Here is the code I think is relevant. The model, which has been passed around as a pointer, has an OnManualSubmit edit strategy.
bool BankDB::Import(QSqlTableModel *thisModel)
{
QString importDate = QDate::currentDate().toString("yyyy-MM-dd") + " " + QTime::currentTime().toString("hh:mm:ss");
for (int counter; counter < thisModel->rowCount(); counter ++)
thisModel->record(counter).setValue(5,importDate);
thisModel->submitAll();
}
I also tried using thisModel.record(counter).field(5).setValue(import Date) but to no avail.
I know I can timestamp the records at the time they are parsed from the CSV and added to the tablemodel, but that strikes me as inelegant. I want the stamp right at the last moment, before the submitAll.
What I am missing? You can't just fiddle with tablemodels as if they were 2D arrays before you write them? Or you can't setValue with a QString? It all compiles and runs fine. Just not the way I want it
Also, is there a nifty way to a change a field to the same value in a whole tablemodel, without looping through it one record at a time?
thanks in advance
John
Bookmarks