PyQt 没有 button.clicked.connect 功能? [英] PyQt no button.clicked.connect function?

查看:124
本文介绍了PyQt 没有 button.clicked.connect 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 python 3.4 的 PyQt4,并且发生了这个奇怪的错误.每当我尝试调用 btn.clicked.connect() 时,Pycharm 都会抛出此错误:

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".

例如:

btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)

会抛出这个错误.如何?我缺少文件吗?

will throw this error. How? Do I have missing files?

推荐答案

根据 事件和信号PyQt4 - PyQt4 教程 - ZetCode:

PyQt4.5 引入了一种新样式的 API 来处理信号和插槽.

PyQt4.5 introduced a new style API for working with signals and slots.

QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'),self.onClicked)

这是旧式 API.

button.clicked.connect(self.onClicked)

新样式更符合 Python 标准.

The new style adheres more to the Python standards.

这篇关于PyQt 没有 button.clicked.connect 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆