diff options
author | Christian Tismer <tismer@stackless.com> | 2019-09-30 13:14:20 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2019-09-30 15:18:45 +0200 |
commit | 63e46f6a0a80cda662be9350923a9e080fac7b6f (patch) | |
tree | 248211da0b9ce2542a2d927f8efc4cb7e934c102 /sources/pyside2 | |
parent | 142d75c30ac18461b350c543d6eb43df1ae60aa4 (diff) |
Fix bad shutdown effect on QApplication.instance()
When
app = QtWidgets.QApplication.instance()
is used before a QApplication has been created, the qApp code
sees no qApp instance in C++ and assumes a shutdown.
This patch keeps track of QApplication being created and
behaves correctly on that aspect.
It is still unsolved that QtCore.QObject.staticMetaObject
gets deleted on a qApp shutdown, which is too much.
I think this can be handled in another patch if at all, since
the shutdown / recreate feature is undocumented and of little use.
Change-Id: I140b6dba45f7cd337580373dbf72bc6d0a625fea
Fixes: PYSIDE-1093
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2')
-rw-r--r-- | sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py index c58aba82e..1c0d5d55d 100644 --- a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py +++ b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py @@ -33,7 +33,10 @@ import PySide2 # It also uses the qApp variable to finish the instance and start over. class qAppMacroTest(unittest.TestCase): + _test_1093_is_first = True + def test_qApp_is_like_a_macro_and_can_restart(self): + self._test_1093_is_first = False from PySide2 import QtCore try: from PySide2 import QtGui, QtWidgets @@ -72,5 +75,20 @@ class qAppMacroTest(unittest.TestCase): # and they are again all the same self.assertTrue(qApp is QtCore.qApp is QtGui.qApp is QtWidgets.qApp) + def test_1093(self): + # Test that without creating a QApplication staticMetaObject still exists. + # Please see https://bugreports.qt.io/browse/PYSIDE-1093 for explanation. + # Note: This test must run first, otherwise we would be mislead! + assert self._test_1093_is_first + from PySide2 import QtCore + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + app = QtCore.QCoreApplication.instance() + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + if app is None: + app = QtCore.QCoreApplication([]) + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + del __builtins__.qApp + + if __name__ == '__main__': unittest.main() |