6

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?

6
  • try: self.button = QtGui.QPushButton('Quit', self) and self.btn.clicked.connect(QtCore.QCoreApplication.instance().quit) Commented Oct 14, 2015 at 17:19
  • Nope, already tried, but sadly not working Commented Oct 14, 2015 at 17:20
  • For sanity check - what's the PyQt's version? Commented Oct 14, 2015 at 17:24
  • 4, Its funny because everything else is working. Commented Oct 14, 2015 at 17:26
  • 1
    A workaround might be self.connect(btn, SIGNAL("clicked()"), the_slot) if self derives from QWidget Commented Oct 14, 2015 at 17:29

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Eh, what "works" here? Python does execute this correctly, yes. But Pycharm and it's Python analysis does still not correctly handle button.clicked.connect(self.onClicked). The warning persists, because it can not defer the type of clicked. Any hints here how to make this work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.