开发者

QT slot get Signaled twice

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 开发者_StackOverflow中文版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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜