<br><br><div class="gmail_quote">2010/3/15 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 Mon, 15 Mar 2010 15:12:01 +0300, z <<a href="http://zoomer.gm" target="_blank">zoomer.gm</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>> wrote:<br>
> 2010/3/15 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>><br>
><br>
>> On Sun, 14 Mar 2010 22:06:02 +0300, z <<a href="http://zoomer.gm" target="_blank">zoomer.gm</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>> wrote:<br>
>> > 2010/3/5 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>><br>
>> ><br>
>> >> 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<br>
>> >> > 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<br>
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<br>
(sipCppV=0x8c6590,<br>
>> >> > sipState=<value optimized out>) at sipQtGuiQSystemTrayIcon.cpp:752<br>
>> >> > #6 0x00007ffff219c289 in sipWrapper_dealloc (self=0x0) at<br>
>> >> > siplib.c:9675<br>
>> >> > #7 0x00007ffff7adc0e5 in subtype_dealloc (self=0x7ffff7f1caf0) at<br>
>> >> > Objects/typeobject.c:1019<br>
>> >> > #8 0x00007ffff7aba0cf in insertdict (mp=0x63cf60,<br>
>> >> > 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<br>
>> >> > Objects/dictobject.c:701<br>
>> >> > #10 0x00007ffff7abe48d in _PyModule_Clear (m=<value optimized out>)<br>
>> >> > at<br>
>> >> > Objects/moduleobject.c:138<br>
>> >> > #11 0x00007ffff7b2ac4f in PyImport_Cleanup () at<br>
Python/import.c:439<br>
>> >> > #12 0x00007ffff7b33c46 in Py_Finalize () at Python/pythonrun.c:434<br>
>> >> > #13 0x00007ffff7b33d58 in Py_Exit (sts=0) at<br>
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<br>
>> >> > (fp=0x7fffffffe578,<br>
>> >> > filename=0x7fffffffe578 "crash.py", closeit=1,<br>
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<br>
>> >> > siplib.c:9675<br>
>> >> > 9675 forgetObject((sipSimpleWrapper *)self);<br>
>> >> > (gdb) f 5<br>
>> >> > #5 0x00007ffff65f347c in release_QSystemTrayIcon<br>
(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<br>
*>(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>
>> >> Crashes on exit like this are caused by Qt objects being deleted in<br>
>> >> the<br>
>> >> "wrong" order. Unfortunately PyQt has (almost) no control over that<br>
>> >> order.<br>
>> >> By adding those dummy functions you are altering the order in which<br>
>> >> things<br>
>> >> get garbage collected. It doesn't happen with C++ applications<br>
because<br>
>> >> the<br>
>> >> objects don't get deleted.<br>
>> >><br>
>> >><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<br>
>> > deleted<br>
>> > afer app.exec_(), all will be fine<br>
>><br>
>> So why would you not add it to a QGraphicsScene?<br>
>><br>
><br>
> In my program, i have several items, which will be added to the scene and<br>
> showed only after some event (button click, for ex.). They are collecting<br>
> data, while not being shown, and therefore should persist during all<br>
> application lifetime. But the user might exit application, and do not<br>
> necessarily trigger their showing action. And application crashes.<br>
<br>
</div></div>Wouldn't it be better to always add the widget to the scene, let Qt create<br>
the proxy for you, and just hide it until it is needed?<br></blockquote><div>Yes, in my usecase it is possible to overcome problem this way. But requiring an item to be in the scene is a bit strict. Putting such a restriction on top of Qt is tricky to find out and debug what's happening. If it can be solved by PyQt itself, the same way as the problem with QSysremTrayIcon - it would save some blood of developers. (And PySide just works ;)<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></blockquote></div><br>