QSqlTableModel::removeRow() does not delete row in SQLite database

1.7k Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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().

0
On

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