开发者

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开发者_如何学C)
        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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜