Skip to content

Commit

Permalink
Make sure QApplication is quit before changing Qt framework
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Feb 23, 2016
1 parent 8d3d551 commit a47fdf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 7 additions & 0 deletions qt_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,15 @@ def reload_qt():
e.g. PySide if PyQt4 is loaded).
"""

# Clear any forbidden modules
_import_hook._forbidden.clear()

# Quit app if active
global qapp
if qapp is not None:
qapp.quit()
qapp = None

global QtCore
global QtGui

Expand Down
11 changes: 1 addition & 10 deletions test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class TestQT(object):

def teardown_class(cls):
for m in sys.modules.keys():
for m in list(sys.modules.keys()):
if m.startswith('PyQt4') or m.startswith('PySide'):
sys.modules.pop(m)

Expand Down Expand Up @@ -62,16 +62,13 @@ def test_load_ui_qt4(self):
app = get_qapp()
load_ui('test.ui')
app.quit()
del app

def test_load_ui_pyside(self):
self._load_pyside()
from qt_helpers import load_ui, get_qapp
app = get_qapp()
load_ui('test.ui')
app.exit()
app.quit()
del app

def test_submodule_import(self):
self._load_qt4()
Expand Down Expand Up @@ -140,8 +137,6 @@ def test_launch_after_reload(self):
time.sleep(0.1)
app.quit()

del app

os.environ['QT_API'] = qt.QT_API_PYQT4
qt.reload_qt()

Expand All @@ -155,8 +150,6 @@ def test_launch_after_reload(self):
time.sleep(0.1)
app.quit()

del app

os.environ['QT_API'] = qt.QT_API_PYSIDE
qt.reload_qt()

Expand All @@ -169,5 +162,3 @@ def test_launch_after_reload(self):
app.flush()
time.sleep(0.1)
app.quit()

del app

0 comments on commit a47fdf0

Please sign in to comment.