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. PyQt5: Closing Main Window from Another File - Multiple Instance Issue
Forum Updated to NodeBB v4.3 + New Features

PyQt5: Closing Main Window from Another File - Multiple Instance Issue

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 239 Views
  • 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.
  • S Offline
    S Offline
    shashanksd
    wrote on last edited by
    #1

    I'm encountering a challenge in my PyQt5 application. I have a main window created in one file (common_methods.py). I want to close this window from another file (Main_controller.py). However, when I attempt to close it, unable to close it

    Below is my code,

    common_methods.py

    class Common_methods:
        def __init__(self):
            pass
    
        def mainScreen(self):
            # Code to create and show the main window
            # ...
            return mainWindow
    

    Main_controller.py

    class Main_controller:
        def __init__(self):
            pass
    
        def newPrj(self):
            common_method_instance = Common_methods()
            mainScreen_instance = common_method_instance.mainScreen()  # Calling mainScreen again?
            mainScreen_instance.close()
    
    JonBJ 1 Reply Last reply
    0
    • S shashanksd

      I'm encountering a challenge in my PyQt5 application. I have a main window created in one file (common_methods.py). I want to close this window from another file (Main_controller.py). However, when I attempt to close it, unable to close it

      Below is my code,

      common_methods.py

      class Common_methods:
          def __init__(self):
              pass
      
          def mainScreen(self):
              # Code to create and show the main window
              # ...
              return mainWindow
      

      Main_controller.py

      class Main_controller:
          def __init__(self):
              pass
      
          def newPrj(self):
              common_method_instance = Common_methods()
              mainScreen_instance = common_method_instance.mainScreen()  # Calling mainScreen again?
              mainScreen_instance.close()
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @shashanksd
      Each time you call common_method_instance.mainScreen() that creates a new mainScreen_instance assuming your comment

      # Code to create and show the main window

      is true, and it is that which you close.

      I'm not saying whether your architecture is good, it's odd, but given what you are doing you need to keep a reference to the initially created main window around somewhere.

      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