簡體   English   中英

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

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

我正在使用PyQT4和Monkey Studio ide編寫我的第一個GUI應用程序。

我制作了一個帶有按鈕的對話框(mainwindow.ui),該按鈕將信號clicked()發送到MainWindow的插槽slot1()

這是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"

它不起作用: AttributeError: 'MainWindow' object has no attribute 'slot1'

我嘗試在def slot1(self) @pyqtSlot("")之前添加@pyqtSlot("") ,但出現此錯誤:NameError:未定義名稱'pyqtSlot'

我也嘗試了@QtCore.pyqtSignature("slot1()") ,沒有任何效果。

原來,我還必須from PyQt4.QtCore import * ,這使我能夠使用@pyqtSlot()

沒有引號,因為那樣會引發另一個C ++錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM