[Qt-interest] Delete Items Problem

Srdjan Todorovic todorovic.s at googlemail.com
Mon Apr 20 14:55:52 CEST 2009


HI,

2009/4/20 Sujan Dasmahapatra <>:
>
> Now  after loading some 3 or 4 geometries if delete the last item
> everythings is fine.But if I delete the first item then some problem is
> happening so that I am not able select the geometry again from the
> QTableWdiget as its crashing.

Debugger, do you use it?!
    (heh, isn't that from Pulp Fiction? ;)   )

> You can see this peace of code. Yo can see these two functions
>  mouseReleaseEvent is there for selecting geometry from the TableWdiget and
> delete part is the mechanism by which I am deleteing parts…….

> void TableWidget::mouseReleaseEvent(QMouseEvent * )
> {
>         if(countTableWidget>=1)
>         {
>         if(item[currentRow()]->isSelected()==true)

currentRow() out of bounds for item[] ?

>         {
>                 if(countTableWidget != 1) {
>                 for(i=0;i<countTableWidget;i++)

eek!

>                 {
>                         if(geoMetry[i]->isSelected()==true)
>                         {
>                               geoMetry[i]->setFlag(QGraphicsItem::ItemIsSelectable,false);
>                               geoMetry[i]->setSelected(false);
>                         }
>                 }
>                 }
>                 selectPart();
>         }
>         }
> }
>
>
> void TableWidget::deletePart()
> {
>         if(geoMetry[currentRow()]->isSelected() == true)
>         {
>            delete geoMetry[currentRow()];

Oh!
What happens if currentRow() is 0?
   BANG! :)

>            removeRow(currentRow());
>            countTableWidget--;

Why keep your own index?

>         if(countTableWidget==0)
>                 {
>                         geoMetry.clear();
>                         item.clear();
>                 }
>         }
> }

Since you're keeping your own index into the geoMetry array, and
deleting using another index, I wonder if you have a mismatch between
your index and the widget's index, as elements get shifted down, but
your index stays uncompacted. (Just a guess)

Anyway, I'm sure a software engineer/project developer such as
yourself would have already used a debugger or at the very least put
in some printlining debug code, so that you can formulate your idea of
what's happening to the objects and variables when you have this
crash. Right?

Good luck though.

Srdjan




More information about the Qt-interest-old mailing list