[Interest] Best way to implement "delete from" when using a QSqlTableModel?

K. Frank kfrank29.c at gmail.com
Sat Jul 7 18:45:42 CEST 2012


Hello List!

I have a QSqlTableModel (connected to a QTableView) that I use
to edit a table in a database.

Specifically, I would like to achieve the effect of:

   delete from my_table where my_column = 'some_value';

I don't see a way to do this directly with QSqlTableModel.  Have I
missed anything?

I see two possibilities:

First, I could identify the rows I wish to delete (e.g., by running a
select query), and then call QSqlTableModel::removeRows on the
rows in question.

Second, I could run "delete from" on the database, and then tell
QSqlTableModel to resynchronize itself with its underlying table.

Third, ???

The tables I'm working with are not particularly large, so efficiency
isn't a primary concern.

Any suggestions for ways to implement "delete from" functionality
would be most appreciated.

Thanks.


K. Frank



More information about the Interest mailing list