[PyQt] Bug report: multiple QApplication instances cause a segfault

Baz Walter bazwal at ftml.net
Wed Jun 22 13:34:33 BST 2011


On 21/06/11 17:04, David Townshend wrote:
> The problem is that creating (and quitting) multiple QApplications in
> succession causes a segfault.  This situation tends to occur in unit tests,
> particularly in testing subclasses of QApplication.
>
> The following snippet illustrates the problem:
>
>>>> >>> from PyQt4 import QtGui
>>>> >>> app = QtGui.QApplication([])
>>>> >>> app.quit()
>>>> >>> app = QtGui.QApplication([])
>>>> >>> app.quit()
>>>> >>> app = QtGui.QApplication([])
> Segmentation fault

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.

this suggests that, in pyqt, something like the following should work:

from PyQt4 import QtGui
QtGui.qApp = app = QtGui.QApplication([])
app.quit()
QtGui.qApp = app = None


More information about the PyQt mailing list