Please destroy the QApplication singleton before creating a new QApplication instance Error
I'm using Python 3.12.2 and PySide6 6.6.3.1 in Ubuntu 22.04, and when I run ppg start or launch main.py I got the following error:
Traceback (most recent call last):
File "/home/user/work/BandwidthBuddy/src/main/python/main.py", line 18, in <module>
window = MyApp()
^^^^^^^
File "/home/user/work/BandwidthBuddy/venv/lib/python3.12/site-packages/ppg_runtime/application_context/__init__.py", line 23, in __init__
super().__init__()
File "/home/user/work/BandwidthBuddy/venv/lib/python3.12/site-packages/ppg_runtime/application_context/__init__.py", line 70, in __init__
self.app
File "/home/user/work/BandwidthBuddy/venv/lib/python3.12/site-packages/ppg_runtime/application_context/__init__.py", line 92, in app
result = self._qt_binding.QApplication([])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance.
I had the exact same error however I'm on Windows 11. I altered my src/main/Python/main.py to this and had no issues when running the 'ppg start' command:
import sys
from PySide6.QtWidgets import QMainWindow, QLabel, QApplication
from ppg_runtime.application_context.PySide6 import ApplicationContext
class MyApp(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
label = QLabel('Hello World!', parent=self)
label.setGeometry(50, 50, 100, 30) # Set position and size of the label
self.responsive_UI()
def responsive_UI(self):
self.resize(250, 150)
if __name__ == '__main__':
appctxt = ApplicationContext()
app = QApplication.instance() or QApplication(sys.argv)
window = MyApp()
window.show()
exit_code = app.exec()
sys.exit(exit_code)
This ensures there's only ever one instance of QApplication. The window should look something like the image below
Hi @cccaballero, @mkodes
Thanks for reporting this issue and for sharing your solution. This error has been identified and was resolved in commit d2db850. The issue affected users with PySide6 version 6.2 and later.
While your solution allows the project to start normally, it's important to note that it results in losing the ability to access static files in a user-friendly manner using the get_resource() method. This could limit some functionalities in your application.
I'm working on a new update that will be released next week. This update will handle most of the current issues with the library and add support for the latest versions of PySide6 and PyInstaller, and I'm including the first official documentation.