Qt 的信号顺序问题(以QListWidget 的itemSelectionChanged为例)

本文探讨了在Qt编程中遇到的信号顺序问题,特别是当使用QListWidget的itemSelectionChanged信号时。作者通过实例描述了一个情况:在删除QTableWidget的选中行后,与itemSelectionChanged信号相连的槽函数调用rowCount()返回了删除前的行数。这个问题也在StackOverflow上有其他人遇到。经过模拟实验,作者推测这可能是由于Qt信号的执行顺序和列表清空操作的异步性质导致。为了解决这个问题,提出了使用Qt::QueuedConnection作为连接类型来确保信号处理的正确顺序。
摘要由CSDN通过智能技术生成

Qt 多信号顺序问题:

5.4在Qt的xchat频道看到的提问:

xVim:

Hi. I have a QTableWidget and delete a selected row from it. Therefore, the itemSelectionChanged signal is triggered, which is connected to my slot s. Why does QTableWidget.rowCount() inside that custom slot s give the wrong number of table entries (the number before the deletion)?

Someone else on stackoverflow has the same (unresolved) problem with a QListWidget: https://stackoverflow.com/q/10682621

I am not sure whether I should file a bug for the wrong result of the rowCount() call - I somehow doubt that it is a bug. But I cannot explain why it gives the wrong value in my code. And other people seem to get the same wrong result.


大意是xVim为QTableWidget的itemSelectionChanged连接了一个自定义的槽,结果清空表格时 与itemSelectionChanged连接的槽调用rowCount()得到的却是清空前的行数。而StackOverflow 中这位 https://stackoverflow.com/q/10682621 也遇到同样问题。

模拟之:

ListWidgetTest.ui:一个带两个默认名称pushB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值