It is a little bit strange
If you call
insertRecord(-1, myrecord);
in QSqlTableModel, the record is written to the database immediately, if the setting is not to submit by hand.
In the datamodel a new "row"/record can be found, but this new record is fully empty. It is not filled with the data I provided by myrecord. Makes this sense?
To fill the empty record in the datamodel you have to invoke submit(). Only then the new record is populated with data from the database?
I do not see any sense in adding an empty record to the datamodel, when you have to call select() either.
I am not sure if I do it right. Any comments?
void DocumentsModel::add(QSqlRecord & record) {
if(insertRecord(-1, record)) {
select(); // really, no other way?
auto id = getLastPrimaryKey();
auto fullpathtarget = getNewPath();;
auto fullpathsource = record.value(DocumentsFieldFilename).toString();
QFile::copy(fullpathsource, fullpathtarget);
auto erg = match(createIndex(0, 0), Qt::DisplayRole, id, -1);
auto row = erg.first().row();
auto index = createIndex(row, fieldIndex(DocumentsFieldFilename));
setData(index, filenamenew);
submit();
}
}
DocumentsModel is a subclass of QSqlTableModel!