简体   繁体   English

在Monkey Studio中使用Python PyQT4插槽和信号

[英]Using Python PyQT4 slots and signals in Monkey Studio

I'm writing my first GUI application using PyQT4 and the Monkey Studio ide. 我正在使用PyQT4和Monkey Studio ide编写我的第一个GUI应用程序。

I've made a dialog (mainwindow.ui) with a button that sends the signal clicked() to the MainWindow's slot slot1() 我制作了一个带有按钮的对话框(mainwindow.ui),该按钮将信号clicked()发送到MainWindow的插槽slot1()

This is the MainWindow code: 这是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"

It does not work: AttributeError: 'MainWindow' object has no attribute 'slot1' 它不起作用: 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 我尝试在def slot1(self) @pyqtSlot("")之前添加@pyqtSlot("") ,但出现此错误:NameError:未定义名称'pyqtSlot'

I've also tried @QtCore.pyqtSignature("slot1()") , to no effect. 我也尝试了@QtCore.pyqtSignature("slot1()") ,没有任何效果。

Turns out I also had to import from PyQt4.QtCore import * , which made me able to use @pyqtSlot() . 原来,我还必须from PyQt4.QtCore import * ,这使我能够使用@pyqtSlot()

Without the quotes, because that would throw another C++ error. 没有引号,因为那样会引发另一个C ++错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM