Fix PyQt4 segfault caused by PySide fix.

I guess PySide saves the QApplication internally, while PyQt4 doesn't.
Saving the QApplication as a global prevents it from getting garbage
collected. Saving the QApplication as an instance variable in the
ImageViewer also works, but that might prevent the ImageViewer from getting
garbage collected in an interactive session. (weakref doesn't seem to work here.)
This commit is contained in:
Tony S Yu
2013-06-25 23:15:42 -05:00
parent c4299c4637
commit e305677de5
+8 -4
View File
@@ -22,15 +22,19 @@ __all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage',
'update_axes_image']
global QApp
def init_qtapp():
"""Initialize QAppliction.
The QApplication needs to be initialized before creating any QWidgets
"""
app = QtGui.QApplication.instance()
if app is None:
app = QtGui.QApplication([])
return app
global QApp
QApp = QtGui.QApplication.instance()
if QApp is None:
QApp = QtGui.QApplication([])
return QApp
def is_event_loop_running(app=None):