views:

240

answers:

1

In QT4.5,

I use a QTableWidget, and I have connected the signal QTableWidget::itemClicked() to a custom slot like this:

connect(_table, SIGNAL(itemClicked(QTableWidgetItem*)), item, SLOT(sloItemClicked(QTableWidgetItem*)));

I create such a connection for each row I add to the table.

The problem is that the slot sloItemClicked get called more than once, it seem that it get called X time where X is the number of row in my table.

But it is calling for the same row all the time. (QTableWidgetItem that I receive is the same).

This is a problem, because when the row is clicked, I delete it. So the next time it gets called, the QTableWidgetItem is no longer valid and it crash.

If I have only one row, everything works as expected..

Any idea?

Thanks

+9  A: 

You should only create the connection once since the signal is a signal on the table and not on an individual QTableWidgetItem. When emitted it will give you the QTableWidgdetItem that you clicked on as the argument.

Troubadour