问题
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
- remove the explicit connect
- rename the button
- 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