[PyQt] Segfault on shutdown after adding a menu to a QMainWindow

Philip Lorenz lorenzph+sip at in.tum.de
Thu Mar 25 22:05:49 GMT 2010


Hi,

I am running PyQt 4.7.2 with Qt 4.6.2. When adding a menu to a 
QMainWindow the program segfaults on shutdown in the QApplication 
deconstructor (qapplication.sip - line 605). This seems to be caused by 
Qt as the newly added QMenu is listed in QApplication::topLevelWidgets() 
even though it has a parent set (therefore it should be deleted by Qt 
itself).

The following example the segfault:

from PyQt4.QtGui import *
import sys

app = QApplication(sys.argv)
w = QMainWindow()
w.show()
# Adding the menu using w.menuBar().addMenu(QMenu("Test")) does not add 
it as a top level widget - hence resulting in no segfault on shutdown
w.menuBar().addMenu("Test")
# Prints QMainWindow as well as QMenu
print QApplication.topLevelWidgets()
app.exec_()

Is this a bug within Qt or can anything be done inside PyQt to avoid 
this crash?

Philip


More information about the PyQt mailing list