[PyQt] QMessagebox in slot terminates application

Marc Nations mnations.lists at gmail.com
Mon Jan 12 16:45:06 GMT 2009


Why are you calling the exec_() function from inside the sys.exit() call?
>From the way it's programmed, it looks like sys.exit() will execute and hold
until it gets a result back from the MessageBox called inside the tray icon.
At that point it's going to exit using the result as it's argument.

If you just select 'OK' then the MessageBox returns a 0, which will then
cause a normal termination the program (exit code 0).



On Mon, Jan 12, 2009 at 10:29 AM, Tim Hoffmann <tim.hoffmann at uni-bonn.de>wrote:

> 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_())
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090112/f974d753/attachment-0001.html


More information about the PyQt mailing list