From e305677de59872674b0b7bb45e81844e1910e2ea Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 25 Jun 2013 23:15:42 -0500 Subject: [PATCH] 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.) --- skimage/viewer/utils/core.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/skimage/viewer/utils/core.py b/skimage/viewer/utils/core.py index 4ec3e1cf..3ac0eef3 100644 --- a/skimage/viewer/utils/core.py +++ b/skimage/viewer/utils/core.py @@ -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):