Qt Code:
  1. model = new QSqlTableModel(this, db1);
  2. model->setTable("subjects");
  3. model->setEditStrategy(QSqlTableModel::OnFieldChange);
  4. model->select();
  5. model->removeColumn(0); // don't show the ID
  6. ui->tableView->setModel(model);
To copy to clipboard, switch view to plain text mode 
Inserting:
Qt Code:
  1. model->insertRow(0);
To copy to clipboard, switch view to plain text mode 
Deleting:
Qt Code:
  1. QModelIndexList selection = ui->tableView->selectionModel()->selectedRows();
  2. if (selection.count())
  3. {
  4. for (int i = 0; i < selection.count(); i++)
  5. {
  6. QModelIndex index = selection.at(i);
  7. qDebug() << index.row();
  8. qDebug() << model->removeRow(selection.at(i).row());
  9. model->select();
  10. qDebug() << model->lastError();
  11. //model->submitAll();
  12. }
  13. //model1->submitAll();
  14. }
To copy to clipboard, switch view to plain text mode 

So, the table displays correctly.
When I edit a cell, the row gets empty and shows !, like it was deleted. Nothing changes in DB.
When I delete a row with algorithm above, removeRow returns true, the table view blinks like it's re-rendering, but nothing changes.
When I insert a row, edit it, it gets empty and shows !, BUT it appears in DB and it's in the table when I reopen the app.
When I un-comment model->submitAll(); nothing changes.
Any ideas?