开发者

QT, QTableWidget: Changing Items with the cellChanged()-signal

开发者 https://www.devze.com 2023-04-06 13:29 出处:网络
I am using a QTableWidget. On the cellChanged()-signal I add or update a row in a sqlite databas开发者_运维知识库e. After executing my SQL statements i want to add a button/CellWidget to an item in th

I am using a QTableWidget. On the cellChanged()-signal I add or update a row in a sqlite databas开发者_运维知识库e. After executing my SQL statements i want to add a button/CellWidget to an item in this row. As this is the change of a cell, it, of course, changes the content of the item and creates a loop.

How do i avoid this loop?


You have an other approach at your disposal. Using a mutex variable (a boolean for instance) that controls if you should add/update a row in your sql database, you can ignore the signal emited after executing SQL statements. The mutex variable can then be released after you added the button to the row.

This approach is probably cheaper than disconnecting/connecting the signal/slot arround your automatic update action. If the signal is often triggered, this might be the solution.


You could check if the cell content has really changed by keeping a copy of the data, either in another container, or under an user defined role in the same cell.

0

精彩评论

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

关注公众号