Skip to content Skip to sidebar Skip to footer

PyQt4 Application On Windows Is Crashing On Exit

I am writting a desktop application with PyQt4 and all of the sudden it started to crash on exit. I reviewed all of my code to make sure I wasn't doing anything funny to make it cr

Solution 1:

I had the same problem with a simple hello world application (QDialog with 20 labels). Weirdly the problem disappears with 10 labels.

I solved by forcing exit as follows:

def closeEvent(self, event):
    exit()

This happens on Windows with PyQt v4.10.3 for Python v2.7 (x32) on VirtualBox.


Solution 2:

A debugger will only tell us what we already know: The application crashes on exit.

You probably need to set an active window which, when closed, will result in deterministic garbage collection and a clean application exit. There are more proper ways to do this, but the simpl;e example below should require minimum code changes, and is based on a dialog application that I wrote and works fine.

#The application
app = QtGui.QApplication(sys.argv)

#The main window
MainWindow = QtGui.QMainWindow()
app.setActiveWindow(MainWindow) #<---- This is what's probably missing

#the ui
ui = Ui_MainWindow()
ui.setupUi(MainWindow)

#start the application's exec loop, return the exit code to the OS
exit(app.exec_())

Post a Comment for "PyQt4 Application On Windows Is Crashing On Exit"