Hello,
I have a QSqlTableModel and its signals rowsInserted and rowsRemoved connected to print their parameters:

Qt Code:
  1. model = new QSqlTableModel;
  2. model->setTable("tab");
  3. model->select();
  4. connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
  5. this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
  6. connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
  7. this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
  8. ...
  9.  
  10. void ETest::sourceRowsInserted(const QModelIndex &source_parent, int start, int end)
  11. {
  12. qDebug() << "rowsInserted" << start << end;
  13. }
  14.  
  15. void ETest::sourceRowsRemoved(const QModelIndex &source_parent, int start, int end)
  16. {
  17. qDebug() << "rowsRemoved" << start << end;
  18. }
  19.  
  20. void ETest::addme()
  21. {
  22. QSqlRecord record = model->record();
  23. model->insertRecord(-1, record);
  24. }
  25.  
  26. void ETest::deleteme()
  27. {
  28. model->removeRow(model->rowCount() - 1);
  29. }
To copy to clipboard, switch view to plain text mode 
When I use OnManualSubmit as strategy it is perfect:
output inserting the fourth row:
rowsInserted 3 3
output removing the fourth row:
rowsRemoved 3 3

But when I use OnFieldChange or OnManualSubmit:
output inserting the fourth row:
rowsInserted 3 3
rowsRemoved 0 3
rowsInserted 0 3
output removing the fourth row:
rowsRemoved 0 3
rowsInserted 0 2

Stepping into Qt, I've found a call to submit and select:

Qt Code:
  1. bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record)
  2. {
  3. ...
  4. if (d->strategy == OnFieldChange || d->strategy == OnRowChange)
  5. return submit();
  6.  
  7. bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
  8. {
  9. ...
  10. switch (d->strategy) {
  11. case OnFieldChange:
  12. case OnRowChange:
  13. ...
  14. select();
To copy to clipboard, switch view to plain text mode 
I suppose this is a wanted behavior but it makes rowsInserted and rowsRemoved signals very hard to use.
I need to make a simple ModelProxy to populate a tree view with a QSqlTableModel, how can I get a clean signal when a row is inserted or removed?