PyQt no button.clicked.connect function?

匿名 (未验证) 提交于 2019-12-03 01:22:02

问题:

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?

回答1:

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!