尽管 pyqtSlot 装饰器,Slot 仍被调用两次 [英] Slot gets called twice despite pyqtSlot decorator

查看:27
本文介绍了尽管 pyqtSlot 装饰器,Slot 仍被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在qt5设计器中制作的一个类.当我点击按钮时,插槽被调用两次.

This is a class which form i made in qt5 designer. The slot is called twice when I click the button.

class CustomerList(QWidget, Ui_CustomerList):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)
        self.buttX.clicked.connect(self.on_buttX_clicked)

    @pyqtSlot()
    def on_buttX_clicked(self):
        print("on_buttX_clicked")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = CustomerList()
    w.show()

    sys.exit(app.exec_())

我在这里错过了什么?

推荐答案

你的按钮在设计器中叫做 buttX,所以 setupUi() 中的Auto connect by name"功能代码> 找到匹配的插槽.

Your button is called buttX in designer, so the "Auto connect by name" feature in setupUi() finds a matching slot.

你可以

  1. 删除显式连接
  2. 重命名按钮
  3. 重命名插槽

我个人会选择后者,即使用不具有自动名称连接"正在寻找的模式的插槽名称.例如.onButtXClicked

I would personally go for the latter, i.e. use a slot name that does not have the pattern the "auto name connect" is looking for. E.g. onButtXClicked

这篇关于尽管 pyqtSlot 装饰器,Slot 仍被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆