This minimal SailfishOS app tries to demonstrate the issues you get when using a QSqlTableModel and trying to remove items from it.
I was first surprised to discover that QSqlTableModel::removeRows doesn't call beginRemoveRows nor endRemoveRows.
I was also surprised to see that rowCount always return the right value when you add items the model, but that it doesn't when you remove items from the model !
Behavior is as follows :
-
With model.editStrategy set to QSqlTableModel::OnManualSubmit :
-
First case : without
beginRemoveRowsandendRemoveRows:- Expected : The database isn't updated unless you call
submitAll. - Unexpected : The view isn't either : the deleted item remains visible in the SilicaListView with original values.
- Unexpected :
rowCountdoesn't return the right value after a deletion. - Expected : Calling
submitAllautomatically callsselectwhich resets the model : if there is a remorse running, the app crashes.
- Expected : The database isn't updated unless you call
-
Second case : with
beginRemoveRowsandendRemoveRows:- Expected : The database isn't updated until you call
submitAll. - Unexpected : The last item of the SilicaListView is removed (!!), no matter what item you wanted to delete.
- Unexpected :
rowCountdoesn't return the right value after a deletion. - Expected : Calling
submitAllautomatically callsselectwhich resets the model : if there is a remorse running, the app crashes.
- Expected : The database isn't updated until you call
-
-
With model.editStrategy set to QSqlTableModel::OnFieldChanged :
-
First case : without
beginRemoveRowsandendRemoveRows:- Expected : The database is updated immediately.
- Unexpected : The deleted item remains visible in the SilicaListView with undefined values unless you call
select. - Unexpected :
rowCountdoesn't return the right value after a deletion. - Expected : Calling
selectrefreshes the model : if there is a remorse running, the app crashes.
-
Second case : with
beginRemoveRowsandendRemoveRows:- Expected : The database is updated immediately.
- Unexpected : The deleted item remains visible in the SilicaListView with undefined values.
- Unexpected : The last item of the SilicaListView is removed (!!), no matter what item you wanted to delete.
- Unexpected :
rowCountdoesn't return the right value after a deletion. - Expected : Calling
selectrefreshes the model : if there is a remorse running, the app crashes.
-
I've tried to keep the code easy to read and understand. Hope this will be useful.