[Qt-interest] How to remove items from QSqlTableModel via QTableView
Sven Grunewaldt
strayer at olle-orks.org
Sat Apr 25 17:58:19 CEST 2009
Haha, oh god. I can't believe I didn't notice this... Thanks! :)
Sometimes you need another pair of eyes to see the obvious.
Regards,
Sven Grunewaldt
Am 25.04.2009 17:50, schrieb Scott Aron Bloom:
> 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
>>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090425/530a4777/attachment.html
More information about the Qt-interest-old
mailing list