I've got PyQt4 with a python 3.4 and there is this strange bug occurring. Whenever I try to call btn.clicked.connect(), Pycharm will throw this error:
Cannot find reference "connect" in "function".
So for example:
btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
will throw this error. How? Do I have missing files?
QPushButton is a simple button in PyQt, when clicked by a user some associated action gets performed. For adding this button into the application, QPushButton class is used. When the button is pressed it should perform some action, in order to add action to a button we will use clicked.connect method.
where button is pyqt QPushButton widget, function is a name of function. In this code, we make btn_search button bind a click event on_file_search. To process button click event, we should define on_file_search () function. Here is an example: on_file_search () will show a dialog to display a text you have entered in a QLineEdit.
Now, as mentioned in previous examples you must create the QApplication which will run your PySide2 code: Let's create the clickable button, a QPushButton. We pass a python string on the constructor which will label the button: Before we show the button, we must connect it to the say_hello () function that we defined previously.
Basically, this Qt feature allows your graphical widgets to communicate with other graphical widgets or your own python code. Our application will create a clickable button which will show Button clicked, Hello! in the python console each time you click it.
According to Events and Signals in PyQt4 - PyQt4 Tutorial - ZetCode:
PyQt4.5 introduced a new style API for working with signals and slots.
QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'),self.onClicked)
This is the old style API.
button.clicked.connect(self.onClicked)
The new style adheres more to the Python standards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With