QSqlTableModel removeRow() not removing records from some tables ?
-
Hi,
I am using a SQLite database. When trying to remove records from some tables; the records are not removed. In the table the record remains although at the bottom it says 1-0 of 1 records. Using the exact same code on a different table it works fine. What could be the issue with removing records from some of these tables ?
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("myDB"); QSqlTableModel *model = new QSqlTableModel; model->setTable("myTable"); model->select(); model->removeRow(0); //Remove row 0.
-
Compare your tables (I would guess your non-working table has no PK) and / or provide a minimal, compilable examples.
Without the tables and some code we can't see what might go wrong. -
@Christian-Ehrlicher I don't believe it is possible to have sqlite with no primary key (the rowid column is always created unless explicitly declared with no rowid but then if no other pk is present this should fail).
@R-P-H please post your code and tables definitions, otherwise we're just whistling in the dark.
-
@Christian-Ehrlicher said in QSqlTableModel removeRow() not removing records from some tables ?:
Compare your tables (I would guess your non-working table has no PK) and / or provide a minimal, compilable examples.
Without the tables and some code we can't see what might go wrong.@Christian-Ehrlicher Thanks, adding a primary key to the tables solved the issue. The tables did have a built in rowid column but it looks like Qt requires a user-defined PK column for it to work.
-
The QSqlTableModel needs a real PK, yes.