[PyQt] QMessagebox in slot terminates application

Tim Hoffmann tim.hoffmann at uni-bonn.de
Mon Jan 12 16:29:52 GMT 2009


I write an application with a trayicon as main interface. When I popup a 
QMessageBox in a slot, the application terminates after closing the box. 
I have no idea why. Termination is regular (exit code 0 and no exception 
is raised). However, if I make the widget visible (uncommenting 
self.show() in example below), termination does not happen.

I'm using Python 2.5 and Pyqt 4.4.3

Thanks



minimal example:
----------------

import sys
from PyQt4 import QtCore, QtGui

class Systray(QtGui.QWidget):
     def __init__(self):
         QtGui.QWidget.__init__(self)
         self.createActions()
         self.createTrayIcon()
         self.trayIcon.show()
     #self.show()

     def createActions(self):
         self.quitAction = QtGui.QAction(self.tr("&Quit"), self)
         QtCore.QObject.connect(self.quitAction, 
QtCore.SIGNAL("triggered()"),

   QtGui.qApp, QtCore.SLOT("quit()"))
         self.testAction = QtGui.QAction(self.tr("Test"),  self)
         QtCore.QObject.connect(self.testAction, 
QtCore.SIGNAL("triggered()"), self.test)

     def createTrayIcon(self):
         self.trayIconMenu = QtGui.QMenu(self)
         self.trayIconMenu.addAction(self.quitAction)
         self.trayIconMenu.addAction(self.testAction)

         self.trayIcon = QtGui.QSystemTrayIcon(self)
         self.trayIcon.setIcon(QtGui.QIcon("test.png"))
         self.trayIcon.setContextMenu(self.trayIconMenu)

     def test(self):
         QtGui.QMessageBox.information(self, "title", "hello")
	# closing this terminates the program

app = QtGui.QApplication(sys.argv)
x = Systray()
sys.exit(app.exec_())


More information about the PyQt mailing list