2011-01-12 65 views
0

我使用PyQt4的和猴子Studio IDE中写我的第一个GUI应用程序。在猴子使用Python PyQt4的插槽和信号工作室

我做了与发送到主窗口的插槽中的信号clicked()slot1()

这是主窗口代码按钮对话框(mainwindow.ui):

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(""),但我得到这个错误: NameError:名字“pyqtSlot”没有定义

我也试过@QtCore.pyqtSignature("slot1()"),没有效果。

回答

2

原来我也不得不进口from PyQt4.QtCore import *,这让我能够使用@pyqtSlot()

没有引号,因为这将引发另一C++错误。