在 Monkey Studio 中使用 Python PyQT4 插槽和信号
我正在使用 PyQT4 和 Monkey Studio ide 编写我的第一个 GUI 应用程序。
我创建了一个带有按钮的对话框 (mainwindow.ui),该按钮将信号 clicked()
发送到 MainWindow 的插槽 slot1()
是 MainWindow 代码:
from PyQt4 import uic
(Ui_MainWindow, QMainWindow) = uic.loadUiType('mainwindow.ui')
class MainWindow (QMainWindow):
"""MainWindow inherits QMainWindow"""
def __init__ (self, parent = None):
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def __del__ (self):
self.ui = None
def slot1(self):
print "Test"
这 不起作用: AttributeError: 'MainWindow' object has no attribute 'slot1'
我尝试在 def slot1(self)< 之前添加
@pyqtSlot("")
/code>,但我收到此错误: NameError:名称'pyqtSlot'未定义
我也尝试过@QtCore.pyqtSignature(“slot1()”)
,但没有效果。
I'm writing my first GUI application using PyQT4 and the Monkey Studio ide.
I've made a dialog (mainwindow.ui) with a button that sends the signal clicked()
to the MainWindow's slot slot1()
This is the MainWindow code:
from PyQt4 import uic
(Ui_MainWindow, QMainWindow) = uic.loadUiType('mainwindow.ui')
class MainWindow (QMainWindow):
"""MainWindow inherits QMainWindow"""
def __init__ (self, parent = None):
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def __del__ (self):
self.ui = None
def slot1(self):
print "Test"
It does not work: AttributeError: 'MainWindow' object has no attribute 'slot1'
I've tried adding @pyqtSlot("")
before def slot1(self)
, but I get this error:
NameError: name 'pyqtSlot' is not defined
I've also tried @QtCore.pyqtSignature("slot1()")
, to no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我还必须导入
from PyQt4.QtCore import *
,这使我能够使用@pyqtSlot()
。没有引号,因为这会引发另一个 C++ 错误。
Turns out I also had to import
from PyQt4.QtCore import *
, which made me able to use@pyqtSlot()
.Without the quotes, because that would throw another C++ error.