I had some trouble with the QDataWidgetMapper/QSqlTableModel. I'm using them in manualsubmit mode as the auto mode has some weirdness as you indicated.
What worked for me is the following:
//inside constructor
model->setTable("unit");
model->select();
model->sort(3,Qt::AscendingOrder);
mapper->setModel(model);
mapper->addMapping(ui->le_Unit, model->fieldIndex("UnitName"));
....
//inside a method where I make some changes to the mapped items
mapper->submit();
model->submitAll();
//inside constructor
model = new QSqlTableModel;
model->setTable("unit");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->sort(3,Qt::AscendingOrder);
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(ui->le_Unit, model->fieldIndex("UnitName"));
....
//inside a method where I make some changes to the mapped items
mapper->submit();
model->submitAll();
To copy to clipboard, switch view to plain text mode
hope this helps
Bookmarks