0

I am using QSqlTableModel/QTableView. editStrategy is OnManualSubmit. I have two buttons Save/Revert. Save's pressed is connected with model's submitAll and Revert's pressed is connected with revertAll. This works perfectly but I want to disable Save And Revert buttons when table doesn't contain any difference with database. So if user changed value of some cell from 5 to 6 my buttons become enabled and if then he changed from 6 to 5 my buttons must again become disabled. Is there a better way for doing this except manually caching model data and comparing with models content on each change?

ArmanHunanyan
  • 905
  • 3
  • 11
  • 24
  • What if you watch `QAbstractItemModel::dataChanged()` signal of your model to know whether the data is changed or not? – vahancho Sep 07 '17 at 09:15
  • Have you tried [isDirty](https://doc.qt.io/qt-5/qsqltablemodel.html#isDirty-1)? Or is it not smart enough to detect manually reverted changes? – ekhumoro Sep 07 '17 at 17:11
  • I do not *think* `QSqlTableModel` retains the "original" values as you change (unlike .NET's `DataRow` which does precisely that). In which case, yes, you will have to implement your own "original value caching model". – JonBrave Sep 15 '17 at 13:32

0 Answers0