2011-01-12 35 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++錯誤。