From bb028b4d86187062dd1d15bdc2c6a717beb6df26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Vo=C3=9F?= Date: Thu, 22 Aug 2024 19:52:51 +0200 Subject: [PATCH] Use more robust way to initialize QApp --- loadscompare/compare.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/loadscompare/compare.py b/loadscompare/compare.py index 53bc655..d498ac1 100644 --- a/loadscompare/compare.py +++ b/loadscompare/compare.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import os +import sys from itertools import compress from pyface.qt import QtCore @@ -41,7 +42,7 @@ def __init__(self): def run(self): # Create the app. - app = QApplication([]) + app = self.initApp() # Init the application's menues, tabs, etc. self.initGUI() # Start the main event loop. @@ -52,10 +53,18 @@ def test(self): This function is intended for CI testing. To test at least some parts of the code, the app is initialized, but never started. Instead, all windows are closed again. """ - app = QApplication([]) + app = self.initApp() self.initGUI() app.closeAllWindows() + def initApp(self): + # Init the QApplication in a robust way. + # See https://stackoverflow.com/questions/54281439/pyside2-not-closing-correctly-with-basic-example + app = QApplication.instance() + if app is None: + app = QApplication(sys.argv) + return app + def initGUI(self): # Use one Widget as a main container. self.container = QWidget()