Slot gets called twice despite pyqtSlot decorator

扶醉桌前 提交于 2019-12-12 04:32:51

问题


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_())

What am I missig here?


回答1:


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

You can either

  1. remove the explicit connect
  2. rename the button
  3. rename the slot

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



来源:https://stackoverflow.com/questions/40945854/slot-gets-called-twice-despite-pyqtslot-decorator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!