<br>Hi Phil,<br><br><br><br>It seems the latest version of PyQt4 still has this bug.<br>My installation:<br><br>* Python 2.7.3<br>* PyQt4 4.9.1<br>* SIP 4.13.1<br>* Mac OS X 10.7.4<br><br>I don't know if it is the same as the quoted below, but very similar, and if i delete the instance of <br>
QSystemTrayIcon before exiting, then everything is fine.<br><br><br>Quote below:<br><br>======================================================<br><br><pre>On Fri, 5 Mar 2010 00:35:21 +0100, Kiwi <<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">spiky.kiwi at gmail.com</a>> wrote:
><i> Hi,
</i>><i> I'm totally new to PyQt programming.
</i>><i> While I was writing a very simple app for the system tray I think I found
</i>a
><i> bug.
</i>><i> Here is a simple testcase:
</i>><i>
</i>><i> # -*- coding: utf-8 -*-
</i>><i> import sys
</i>><i> from PyQt4 import QtGui, QtCore
</i>><i>
</i>><i> app = QtGui.QApplication(sys.argv)
</i>><i>
</i>><i> tray = QtGui.QSystemTrayIcon()
</i>><i>
</i>><i> def a(): pass
</i>><i> def b(): pass
</i>><i> def c(): pass
</i>><i> def d(): pass
</i>><i> def e(): pass
</i>><i> def f(): pass
</i>><i> def g(): pass
</i>><i> def h(): pass
</i>><i> def i(): pass
</i>><i> def j(): pass
</i>><i> def k(): pass
</i>><i>
</i>><i> cm = QtGui.QMenu()
</i>><i> cm.addAction("Exit",QtGui.QApplication.quit)
</i>><i>
</i>><i> tray.setContextMenu(cm)
</i>><i>
</i>><i> tray.show()
</i>><i> sys.exit(app.exec_())
</i>><i>
</i>><i>
</i>><i> note that the "defs" are needed to make the crash happen.
</i>><i> FYI, running linux on x86_64
</i>><i> versions:
</i>><i> qt: 4.6.2
</i>><i> pyqt: 4 4.7
</i>><i> sip: 4.10
</i>><i> python: 2.6.4
</i>><i> gcc: 4.4.3
</i>><i> libX11 1.3.3
</i>><i>
</i>><i> here is the backtrace:
</i>><i> (gdb) run
</i>><i> Starting program: /usr/bin/python2.6 crash.py
</i>><i> [Thread debugging using libthread_db enabled]
</i>><i> QSystemTrayIcon::setVisible: No Icon set
</i>><i>
</i>><i> Program received signal SIGSEGV, Segmentation fault.
</i>><i> XFreeColormap (dpy=0x0, cmap=16777218) at FreeCmap.c:41
</i>><i> 41 FreeCmap.c: No such file or directory.
</i>><i> in FreeCmap.c
</i>><i> (gdb) bt
</i>><i> #0 XFreeColormap (dpy=0x0, cmap=16777218) at FreeCmap.c:41
</i>><i> #1 0x00007ffff5f1b558 in ~QSystemTrayIconSys (this=0x9c3070,
</i>><i> __in_chrg=<value optimized out>) at util/qsystemtrayicon_x11.cpp:213
</i>><i> #2 0x00007ffff5f19ff4 in QSystemTrayIconPrivate::remove_sys
</i>><i> (this=0x9bc310) at util/qsystemtrayicon_x11.cpp:352
</i>><i> #3 0x00007ffff5f0637f in ~QSystemTrayIcon (this=0x8c6590,
</i>><i> __in_chrg=<value optimized out>) at util/qsystemtrayicon.cpp:152
</i>><i> #4 0x00007ffff65f46f2 in ~sipQSystemTrayIcon (this=0x8c6590,
</i>><i> __in_chrg=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:137
</i>><i> #5 0x00007ffff65f347c in release_QSystemTrayIcon (sipCppV=0x8c6590,
</i>><i> sipState=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:752
</i>><i> #6 0x00007ffff219c289 in sipWrapper_dealloc (self=0x0) at siplib.c:9675
</i>><i> #7 0x00007ffff7adc0e5 in subtype_dealloc (self=0x7ffff7f1caf0) at
</i>><i> Objects/typeobject.c:1019
</i>><i> #8 0x00007ffff7aba0cf in insertdict (mp=0x63cf60, key=0x7ffff7f08870,
</i>><i> hash=2314047222216391292, value=0x7ffff7dab5d0) at
</i>><i> Objects/dictobject.c:459
</i>><i> #9 0x00007ffff7abcb15 in PyDict_SetItem (op=0x63cf60,
</i>><i> key=0x7ffff7f08870, value=0x7ffff7dab5d0) at Objects/dictobject.c:701
</i>><i> #10 0x00007ffff7abe48d in _PyModule_Clear (m=<value optimized out>) at
</i>><i> Objects/moduleobject.c:138
</i>><i> #11 0x00007ffff7b2ac4f in PyImport_Cleanup () at Python/import.c:439
</i>><i> #12 0x00007ffff7b33c46 in Py_Finalize () at Python/pythonrun.c:434
</i>><i> #13 0x00007ffff7b33d58 in Py_Exit (sts=0) at Python/pythonrun.c:1714
</i>><i> #14 0x00007ffff7b33e87 in handle_system_exit () at
</i>Python/pythonrun.c:1116
><i> #15 0x00007ffff7b340cd in PyErr_PrintEx (set_sys_last_vars=1) at
</i>><i> Python/pythonrun.c:1126
</i>><i> #16 0x00007ffff7b345a6 in PyRun_SimpleFileExFlags (fp=0x7fffffffe578,
</i>><i> filename=0x7fffffffe578 "crash.py", closeit=1, flags=0x7fffffffe0d0)
</i>><i> at Python/pythonrun.c:935
</i>><i> #17 0x00007ffff7b40721 in Py_Main (argc=-134926176, argv=<value
</i>><i> optimized out>) at Modules/main.c:599
</i>><i> #18 0x00007ffff74ebbbd in __libc_start_main (main=<value optimized
</i>><i> out>, argc=<value optimized out>, ubp_av=<value optimized out>,
</i>><i> init=<value optimized out>,
</i>><i> fini=<value optimized out>, rtld_fini=<value optimized out>,
</i>><i> stack_end=0x7fffffffe1e8) at libc-start.c:220
</i>><i> #19 0x00000000004006b
</i>><i> (gdb) f 6
</i>><i> #6 0x00007ffff219c289 in sipWrapper_dealloc (self=0x0) at siplib.c:9675
</i>><i> 9675 forgetObject((sipSimpleWrapper *)self);
</i>><i> (gdb) f 5
</i>><i> #5 0x00007ffff65f347c in release_QSystemTrayIcon (sipCppV=0x8c6590,
</i>><i> sipState=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:752
</i>><i> warning: Source file is more recent than executable.
</i>><i> 752 delete reinterpret_cast<QSystemTrayIcon *>(sipCppV);
</i>><i> Current language: auto
</i>><i> The current source language is "auto; currently c++".
</i>><i> (gdb) f 4
</i>><i> #4 0x00007ffff65f46f2 in ~sipQSystemTrayIcon (this=0x8c6590,
</i>><i> __in_chrg=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:137
</i>><i> 137 }
</i>
Crashes on exit like this are caused by Qt objects being deleted in the
"wrong" order. Unfortunately PyQt has (almost) no control over that order.
By adding those dummy functions you are altering the order in which things
get garbage collected. It doesn't happen with C++ applications because the
objects don't get deleted.
The workaround is to experiment with explicitly deleting objects after
exec_() returns but before sys.exit() is called. In this case "del tray"
seems to avoid the crash.
That said, PyQt does have a mechanism for making sure certain objects get
deleted before the QApplication does - and it seems that QSystemTrayIcon
should also be handled that way. The change will be in tonight's snapshot.
Phil
</pre>======================================================<br><br><br><br>In my code ,after a long time debugging, i just found if i commented out the following code:<br><br>self.trayNotifier = QtGui.QSystemTrayIcon(QtGui.QIcon('images/trayIcon.png'))<br>
self.trayNotifier.show()<br><br>Then no crash on exit. <br>Otherwise, every time i quit my app, crashing windows pop up with the following information leave in terminal:<br><br>Segmentation fault: 11<br><br>And the crashing information inside the pop-up window is attached.<br>
<br><br><br clear="all">Gui<br>