Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. [PySide2] Destroying the QApplication instance and creating another one gives an error
Forum Updated to NodeBB v4.3 + New Features

[PySide2] Destroying the QApplication instance and creating another one gives an error

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    canol
    wrote on last edited by
    #1

    Hello I have a simple app which creates an application, destroys it and then creates another application again.

    It works with PyQt5, but fails with PySide2, giving "RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance.". But I am already destroying the QApplication instance, or at least I think I am destroying it via "del app":

    import sys
    from PySide2.QtWidgets import *
    
    app = QApplication(sys.argv)
    label = QLabel("Hello World")
    label.show()
    app.exec_()
    
    del app
    
    app = QApplication(sys.argv)
    label = QLabel("Hello World")
    label.show()
    app.exec_()
    
    sys.exit()
    

    What might be the problem?

    JonBJ 1 Reply Last reply
    1
    • C canol

      Hello I have a simple app which creates an application, destroys it and then creates another application again.

      It works with PyQt5, but fails with PySide2, giving "RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance.". But I am already destroying the QApplication instance, or at least I think I am destroying it via "del app":

      import sys
      from PySide2.QtWidgets import *
      
      app = QApplication(sys.argv)
      label = QLabel("Hello World")
      label.show()
      app.exec_()
      
      del app
      
      app = QApplication(sys.argv)
      label = QLabel("Hello World")
      label.show()
      app.exec_()
      
      sys.exit()
      

      What might be the problem?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @canol
      You should perhaps coordinate this question with https://forum.qt.io/topic/110418/how-to-destroy-a-singleton-and-then-create-a-new-one, which seems to be the same on-going question.

      From what I have seen del app should work, but you say it does not from PySide2. If so, good luck, because I haven't come across a different answer for PySide2....

      1 Reply Last reply
      1
      • C Offline
        C Offline
        canol
        wrote on last edited by
        #3

        Closing this thread so that we can continue from the other thread, thanks for the input.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved