pythonpysideqlineeditqlcdnumber

Python: Connect QlineEdit with QlcdNumber via button


Why doesn't the content of the edit box get transferred into the lcdNumber field?

class MainDialog (QDialog, MultiTool_widget_ui.Ui_Form):
    def __init__(self):
        #super(MainDialog, self).__init__() OR <next line>
        QDialog.__init__(self)
        self.setupUi(self)
        self.connect(self.pushButton, SIGNAL("clicked()"),self.lcdNumber.display(self.lineEdit.text()))    

Solution

  • Signals must be connected to a callable object. But in your example:

        self.connect(self.pushButton, SIGNAL("clicked()"),
            self.lcdNumber.display(self.lineEdit.text()))
    

    you are actually passing in the return value of the display() method, which in this case, is None.

    To fix your example, you can use a lambda function, like this:

        self.pushButton.clicked.connect(
            lambda: self.lcdNumber.display(self.lineEdit.text()))
    

    Now you are passing in a function object, which will be called when the signal is fired.