Недавно начал разбираться с PyQt4, и у меня возникла довольно странная проблема.
Есть вот такой код:
QtCore.QObject.connect(myclass.mnuExit, QtCore.SIGNAL("activated()"),quit())
Полный код:
модуль frmMain.py (преобразован из *ui файла)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'frmMain.ui'
#
# Created: Tue Jul 6 19:30:01 2010
# by: PyQt4 UI code generator 4.7.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_frmMain(object):
def setupUi(self, frmMain):
frmMain.setObjectName("frmMain")
frmMain.resize(531, 361)
self.centralwidget = QtGui.QWidget(frmMain)
self.centralwidget.setObjectName("centralwidget")
frmMain.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(frmMain)
self.menubar.setGeometry(QtCore.QRect(0, 0, 531, 21))
self.menubar.setObjectName("menubar")
self.mnuMsg = QtGui.QMenu(self.menubar)
self.mnuMsg.setObjectName("mnuMsg")
self.mnuFile = QtGui.QMenu(self.menubar)
self.mnuFile.setObjectName("mnuFile")
frmMain.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(frmMain)
self.statusbar.setObjectName("statusbar")
frmMain.setStatusBar(self.statusbar)
self.mnuExit = QtGui.QAction(frmMain)
self.mnuExit.setObjectName("mnuExit")
self.mnuHello = QtGui.QAction(frmMain)
self.mnuHello.setObjectName("mnuHello")
self.mnuBye = QtGui.QAction(frmMain)
self.mnuBye.setObjectName("mnuBye")
self.mnuMsg.addAction(self.mnuHello)
self.mnuMsg.addAction(self.mnuBye)
self.mnuFile.addAction(self.mnuExit)
self.menubar.addAction(self.mnuFile.menuAction())
self.menubar.addAction(self.mnuMsg.menuAction())
self.retranslateUi(frmMain)
QtCore.QMetaObject.connectSlotsByName(frmMain)
def retranslateUi(self, frmMain):
frmMain.setWindowTitle(QtGui.QApplication.translate("frmMain", "Проверка PyQt4", None, QtGui.QApplication.UnicodeUTF8))
self.mnuMsg.setTitle(QtGui.QApplication.translate("frmMain", "Сообщения", None, QtGui.QApplication.UnicodeUTF8))
self.mnuFile.setTitle(QtGui.QApplication.translate("frmMain", "Файл", None, QtGui.QApplication.UnicodeUTF8))
self.mnuExit.setText(QtGui.QApplication.translate("frmMain", "Выход", None, QtGui.QApplication.UnicodeUTF8))
self.mnuHello.setText(QtGui.QApplication.translate("frmMain", "Приветствие", None, QtGui.QApplication.UnicodeUTF8))
self.mnuBye.setText(QtGui.QApplication.translate("frmMain", "Поздравление", None, QtGui.QApplication.UnicodeUTF8))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="sturmvogel"
__date__ ="$6.7.2010 16.48.04$"
import frmMain
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore
class MyClass(QMainWindow,
frmMain.Ui_frmMain):
def __init__(self, parent=None):
super(MyClass, self).__init__(parent)
self.setupUi(self)
def main():
app = QApplication(sys.argv)
myclass = MyClass()
QtCore.QObject.connect(myclass.mnuExit, QtCore.SIGNAL("activated()"),quit())
myclass.show()
app.exec_()
if __name__ == "__main__":
main()