Just a bit of a pedantic question, but I'm getting a "Cannot find reference 'connect' in function" warning in PyCharm. (Relating to my returnPressed.connect) Is it just a PyCharm bug or the function is deprecated, I couldn't find information on this online.
I am only getting this .connect error on "returnPressed" all the rest are perfectly fine. It is my only warnings left and it bugs the hell out of me.
class Login(QWidget):
switch_window = QtCore.pyqtSignal()
def __init__(self):
QtWidgets.QWidget.__init__(self)
...
self.password = QLineEdit(self)
self.password.setGeometry(QRect(50, 368, 200, 25))
self.password.setFont(QtGui.QFont("Times", 13))
self.password.setAlignment(QtCore.Qt.AlignCenter)
self.password.setEchoMode(QLineEdit.Password)
self.password.setStyleSheet("QLineEdit {border-radius: 10px}")
self.password.setPlaceholderText("Password")
self.password.returnPressed.connect(self.authenticate)
...
def authenticate(self):
...
self.switch_window.emit()
...
This seems to be an issue with the PyQt5 stub file "QtCore.pyi". Here are 2 alternative solutions to fix it:
You could ignore any instances of a pyqtBoundSignal's connect method. To do this, go to "Settings > Editor > Inspections > Python > Unresolved references", and add PyQt5.QtCore.pyqtBoundSignal.connect to the list under "Ignore references"

As explained here, you could modify the stub file named "QtCore.pyi", which can be found in the tree view in PyCharm under "\site-packages\PyQt5".

After opening QtCore.pyi, make sure you see both of the def connect() lines and both of the def emit() lines below. If they are missing, you can add them, and the relevant PyCharm warnings should disappear.
# Support for new-style signals and slots.
class pyqtSignal:
signatures = ... # type: typing.Tuple[str, ...]
def __init__(self, *types: typing.Any, name: str = ...) -> None: ...
@typing.overload
def __get__(self, instance: None, owner: typing.Type['QObject']) -> 'pyqtSignal': ...
@typing.overload
def __get__(self, instance: 'QObject', owner: typing.Type['QObject']) -> 'pyqtBoundSignal': ...
def connect(self, slot: 'PYQT_SLOT') -> 'QMetaObject.Connection': ...
def emit(self, *args: typing.Any) -> None: ...
class pyqtBoundSignal:
signal = ... # type: str
def __getitem__(self, key: object) -> 'pyqtBoundSignal': ...
def connect(self, slot: 'PYQT_SLOT') -> 'QMetaObject.Connection': ...
@typing.overload
def disconnect(self) -> None: ...
@typing.overload
def disconnect(self, slot: typing.Union['PYQT_SLOT', 'QMetaObject.Connection']) -> None: ...
def emit(self, *args: typing.Any) -> None: ...
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