<div class="gmail_quote">On Wed, Jun 22, 2011 at 2:34 PM, Baz Walter <span dir="ltr"><<a href="mailto:bazwal@ftml.net">bazwal@ftml.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 21/06/11 17:04, David Townshend wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The problem is that creating (and quitting) multiple QApplications in<br>
succession causes a segfault. This situation tends to occur in unit tests,<br>
particularly in testing subclasses of QApplication.<br>
<br>
The following snippet illustrates the problem:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>> from PyQt4 import QtGui<br>
>>> app = QtGui.QApplication([])<br>
>>> app.quit()<br>
>>> app = QtGui.QApplication([])<br>
>>> app.quit()<br>
>>> app = QtGui.QApplication([])<br>
</blockquote></blockquote></blockquote>
Segmentation fault<br>
</blockquote>
<br></div>
according to the qt docs, only one application object should be created at a time, and there is a global qApp pointer which refers to the current instance.<br>
<br>
this suggests that, in pyqt, something like the following should work:<br>
<br>
from PyQt4 import QtGui<br>
QtGui.qApp = app = QtGui.QApplication([])<br>
app.quit()<br>
QtGui.qApp = app = None<br>
______________________________<u></u>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.<u></u>com/mailman/listinfo/pyqt</a><br>
</blockquote></div><br><div>I've investigated further and found that its caused by the gtk style which I am using, since I am running gnome. Simply changing the qt style avoids the problem. I recall reading about similar issues before with the gtk-qt style, so I think that this is a know problem. However, I noticed that after changing the style, python still segfaults on exit. gdb indicates that it is something in the QApplication destructor, and it seems that deleting the instance after quitting solves this, e.g.:</div>
<div><br></div><div><div>>>> from PyQt4.QtGui import QApplication</div><div>>>> for i in range(10):</div><div>... app = QApplication([])</div><div>... app.quit()</div><div>... del app</div><div>
... </div><div>>>> exit()</div></div><div><br></div><div>I experimented a bit with setting qApp = None, but it didn't make a difference.</div>