Skip to content

Commit

Permalink
Use more robust way to initialize QApp
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneVoss committed Aug 22, 2024
1 parent 41a19c0 commit bb028b4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions loadscompare/compare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
import sys
from itertools import compress

from pyface.qt import QtCore
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit bb028b4

Please sign in to comment.