[Qt-interest] How to remove items from QSqlTableModel via QTableView
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Sat Apr 25 17:50:49 CEST 2009
Your algorithm fails for the same reason this algorithm fails:
QList< int > values;
//make a list where value[ ii ] == ii
for( int ii = 0; ii < 10; ++ii )
values << ii;
// remove value 3, 4, 5
values.removeAt( 3 );
values.removeAt( 4 );
values.removeAt( 5 );
// which actually removes 3,5 and 7 (I think... :) )
The problem is, since you are removing index.row() 1 at a time, your row
value will most likely NOT be valid after the remove.
Scott
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Sven Grunewaldt
> Sent: Saturday, April 25, 2009 8:31 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] How to remove items from QSqlTableModel via
QTableView
>
> Hi,
>
> I have a QTableView which lies on top of a QSqlTableModel and a Button
> to remove the currently selected rows. It seems that my implementation
> of the buttons function does something wrong.
> Sometimes not all selected items are removed and I just can't see why,
> maybe someone finds my mistake:
>
> void BerichteOrk::on_removeSchuleButton_clicked()
> {
> const QModelIndexList tmp =
> schuleView->selectionModel()->selectedIndexes();
>
> foreach (QModelIndex index, tmp)
> {
> schuleModel->removeRow(index.row());
> }
> }
>
> Regards,
> Sven Grunewaldt
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list