<br><div class="gmail_quote">2010/3/5 Phil Thompson <span dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On Fri, 5 Mar 2010 00:35:21 +0100, Kiwi <<a href="mailto:spiky.kiwi@gmail.com">spiky.kiwi@gmail.com</a>> wrote:<br>
> Hi,<br>
> I'm totally new to PyQt programming.<br>
> While I was writing a very simple app for the system tray I think I found<br>
a<br>
> bug.<br>
> Here is a simple testcase:<br>
><br>
> # -*- coding: utf-8 -*-<br>
> import sys<br>
> from PyQt4 import QtGui, QtCore<br>
><br>
> app = QtGui.QApplication(sys.argv)<br>
><br>
> tray = QtGui.QSystemTrayIcon()<br>
><br>
> def a(): pass<br>
> def b(): pass<br>
> def c(): pass<br>
> def d(): pass<br>
> def e(): pass<br>
> def f(): pass<br>
> def g(): pass<br>
> def h(): pass<br>
> def i(): pass<br>
> def j(): pass<br>
> def k(): pass<br>
><br>
> cm = QtGui.QMenu()<br>
> cm.addAction("Exit",QtGui.QApplication.quit)<br>
><br>
> tray.setContextMenu(cm)<br>
><br>
> tray.show()<br>
> sys.exit(app.exec_())<br>
><br>
><br>
> note that the "defs" are needed to make the crash happen.<br>
> FYI, running linux on x86_64<br>
> versions:<br>
> qt: 4.6.2<br>
> pyqt: 4 4.7<br>
> sip: 4.10<br>
> python: 2.6.4<br>
> gcc: 4.4.3<br>
> libX11 1.3.3<br>
><br>
> here is the backtrace:<br>
> (gdb) run<br>
> Starting program: /usr/bin/python2.6 crash.py<br>
> [Thread debugging using libthread_db enabled]<br>
> QSystemTrayIcon::setVisible: No Icon set<br>
><br>
> Program received signal SIGSEGV, Segmentation fault.<br>
> XFreeColormap (dpy=0x0, cmap=16777218) at FreeCmap.c:41<br>
> 41 FreeCmap.c: No such file or directory.<br>
> in FreeCmap.c<br>
> (gdb) bt<br>
> #0 XFreeColormap (dpy=0x0, cmap=16777218) at FreeCmap.c:41<br>
> #1 0x00007ffff5f1b558 in ~QSystemTrayIconSys (this=0x9c3070,<br>
> __in_chrg=<value optimized out>) at util/qsystemtrayicon_x11.cpp:213<br>
> #2 0x00007ffff5f19ff4 in QSystemTrayIconPrivate::remove_sys<br>
> (this=0x9bc310) at util/qsystemtrayicon_x11.cpp:352<br>
> #3 0x00007ffff5f0637f in ~QSystemTrayIcon (this=0x8c6590,<br>
> __in_chrg=<value optimized out>) at util/qsystemtrayicon.cpp:152<br>
> #4 0x00007ffff65f46f2 in ~sipQSystemTrayIcon (this=0x8c6590,<br>
> __in_chrg=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:137<br>
> #5 0x00007ffff65f347c in release_QSystemTrayIcon (sipCppV=0x8c6590,<br>
> sipState=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:752<br>
> #6 0x00007ffff219c289 in sipWrapper_dealloc (self=0x0) at siplib.c:9675<br>
> #7 0x00007ffff7adc0e5 in subtype_dealloc (self=0x7ffff7f1caf0) at<br>
> Objects/typeobject.c:1019<br>
> #8 0x00007ffff7aba0cf in insertdict (mp=0x63cf60, key=0x7ffff7f08870,<br>
> hash=2314047222216391292, value=0x7ffff7dab5d0) at<br>
> Objects/dictobject.c:459<br>
> #9 0x00007ffff7abcb15 in PyDict_SetItem (op=0x63cf60,<br>
> key=0x7ffff7f08870, value=0x7ffff7dab5d0) at Objects/dictobject.c:701<br>
> #10 0x00007ffff7abe48d in _PyModule_Clear (m=<value optimized out>) at<br>
> Objects/moduleobject.c:138<br>
> #11 0x00007ffff7b2ac4f in PyImport_Cleanup () at Python/import.c:439<br>
> #12 0x00007ffff7b33c46 in Py_Finalize () at Python/pythonrun.c:434<br>
> #13 0x00007ffff7b33d58 in Py_Exit (sts=0) at Python/pythonrun.c:1714<br>
> #14 0x00007ffff7b33e87 in handle_system_exit () at<br>
Python/pythonrun.c:1116<br>
> #15 0x00007ffff7b340cd in PyErr_PrintEx (set_sys_last_vars=1) at<br>
> Python/pythonrun.c:1126<br>
> #16 0x00007ffff7b345a6 in PyRun_SimpleFileExFlags (fp=0x7fffffffe578,<br>
> filename=0x7fffffffe578 "crash.py", closeit=1, flags=0x7fffffffe0d0)<br>
> at Python/pythonrun.c:935<br>
> #17 0x00007ffff7b40721 in Py_Main (argc=-134926176, argv=<value<br>
> optimized out>) at Modules/main.c:599<br>
> #18 0x00007ffff74ebbbd in __libc_start_main (main=<value optimized<br>
> out>, argc=<value optimized out>, ubp_av=<value optimized out>,<br>
> init=<value optimized out>,<br>
> fini=<value optimized out>, rtld_fini=<value optimized out>,<br>
> stack_end=0x7fffffffe1e8) at libc-start.c:220<br>
> #19 0x00000000004006b<br>
> (gdb) f 6<br>
> #6 0x00007ffff219c289 in sipWrapper_dealloc (self=0x0) at siplib.c:9675<br>
> 9675 forgetObject((sipSimpleWrapper *)self);<br>
> (gdb) f 5<br>
> #5 0x00007ffff65f347c in release_QSystemTrayIcon (sipCppV=0x8c6590,<br>
> sipState=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:752<br>
> warning: Source file is more recent than executable.<br>
> 752 delete reinterpret_cast<QSystemTrayIcon *>(sipCppV);<br>
> Current language: auto<br>
> The current source language is "auto; currently c++".<br>
> (gdb) f 4<br>
> #4 0x00007ffff65f46f2 in ~sipQSystemTrayIcon (this=0x8c6590,<br>
> __in_chrg=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:137<br>
> 137 }<br>
<br>
</div></div>Crashes on exit like this are caused by Qt objects being deleted in the<br>
"wrong" order. Unfortunately PyQt has (almost) no control over that order.<br>
By adding those dummy functions you are altering the order in which things<br>
get garbage collected. It doesn't happen with C++ applications because the<br>
objects don't get deleted.<br>
<br></blockquote><div><br>I found another problem, which i think is also caused by delete order:<br>######<br>app = QApplication(sys.argv)<br><br>pushButton = QPushButton()<br>gProxyButton = QGraphicsProxyWidget()<br>gProxyButton.setWidget(pushButton)<br>
<br>view = QGraphicsView()<br>view.show()<br><br>app.exec_()<br>sys.exit()<br>######<br>on exit this program will crash with segfault.<br>but if the proxy widget will be added to the scene, or explicitly deleted afer app.exec_(), all will be fine<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
The workaround is to experiment with explicitly deleting objects after<br>
exec_() returns but before sys.exit() is called. In this case "del tray"<br>
seems to avoid the crash.<br>
<br>
That said, PyQt does have a mechanism for making sure certain objects get<br>
deleted before the QApplication does - and it seems that QSystemTrayIcon<br>
should also be handled that way. The change will be in tonight's snapshot.<br></blockquote><div> </div><div>So can the problem i described also be fixed the same way, as the OP says (i.e. make QGraphicsProxyWidget deleted before QApplication) ?<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888"><br>
Phil<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</div></div></blockquote></div><br>