简体   繁体   中英

Using Python PyQT4 slots and signals in Monkey Studio

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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