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

Baz Walter bazwal at ftml.net
Wed Jun 22 23:17:04 BST 2011

On 22/06/11 20:49, David Townshend wrote:
> On Wed, Jun 22, 2011 at 2:34 PM, Baz Walter<bazwal at ftml.net>  wrote:
>> 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
> 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.:
>>>> from PyQt4.QtGui import QApplication
>>>> for i in range(10):
> ...     app = QApplication([])
> ...     app.quit()
> ...     del app
> ...
>>>> exit()
> I experimented a bit with setting qApp = None, but it didn't make a
> difference.

my point was simply that you need to make sure you remove all references 
to the current qpplication instance before creating a new one.

in general, setting qApp to the instance of qapplication isn't 
necessary. but it's worth noting that qApp won't refer to the same 
*pyqt* object unless it's explicitly over-written. this may become 
relevant when working with subclasses of qapplication. of course, if you 
don't use qApp, it won't make any difference, as you say ;-)

More information about the PyQt mailing list