PDA

View Full Version : QtSqlQueryModel removeRow's problem



qtman
25th February 2008, 16:20
hi guys,I had to ask for help.thanks advance!:)
my problem is the removeRow method in mycode never succeed:



QSqlQueryModel *model;
model->setQuery("select * from person");
QTableView *view = new QTableView;
view->setModel(model);


ok,I can get 7 rows from the person table.
now I try


model->removeRow(0);
model->removeRow(1);
...

however,It donse't work。everything in the view still stay.

but if I use the flowing code:


QSqlRelationalTableModel plainModel;
plainModel.setTable("person");
plainModel.select();
QTableView *view = new QTableView;
view->setModel(&plaiModel);

plainModel.removeRow(0);


Ok,It works. there is 6 rows left in the view.

so ,whats my problem in my first case? how can i resolve it?:confused:
need i change any thing from QSqlQueryModel to QSqlRelationTableModel?
but I would like to use setQuery method than setTable method.

so ,give a help ,please.

thx
:p

wysota
25th February 2008, 16:28
QSqlQueryModel is a read only model, you can't remove rows from it.

qtman
26th February 2008, 02:09
yeah, with QSqlQueryModel read only.
I want to have something ,

perhaps I have 7 rows in the table,
I just want to delete some rows from the QTableView,
not delete the record in the database,how can I do??

can u give me a point? thx

wysota
26th February 2008, 11:28
Apply a QSortFilterProxyModel or set a condition on the query so that you only retrieve the rows you need from the database.