1

I use Windows, C++ and Qt 5.11.1. I have a simple single-table SQLite database. This table "templates" contains primary key: id INTEGER PRIMARY KEY.When I try to remove a single row in "templates" (using QSqlTableModel), m_model.removeRow(0) returns true and submitAll() returns true. But the table still owns that row. I've found that Qt generated the following SQL:

DELETE FROM templates WHERE "templates"."id" IS NULL.
I suppose that the problem is linked with QSqlRecord::isGenerated. How can I fix this error?

ilya
  • 1,103
  • 14
  • 36

2 Answers2

3

As QSqlTableModel::removeRows documentation :

Deletions are submitted immediately to the database. The model retains a blank row for successfully deleted row until refreshed with select().

Kerem
  • 85
  • 1
  • 11
  • I didn't use `select()`. I will add it. But I re-opened the database file (sometimes with 3rd party GUI tool) - no modifications were found. So the SQL query is invalid. – ilya Nov 07 '18 at 08:08
0

Sorry, the reason was in overriden data() method in QSqlTableModel descendant. record() method required data(index, Qt::EditRole).

ilya
  • 1,103
  • 14
  • 36