user765443
user765443

Reputation: 1892

close qt application through program

I have written small tool and works well. I would like to system testing where I can open window and close window to run high level flow. But I am not able to figure to close window through program. One silly option is, to kill process to close window but I feel there could be some better way.

Just sharing invoking code

self.logger.info("Running gui mode")
        if self.approval:
            app = QApplication([])
            window = ApprovalWindow(app, self.block, self.mil, 
                                    self.vio, self.app, 
                                    self.prep, self.logger)
        else:
            app = QApplication([])
            window = ReviewWindow(app, self.block, self.mil, 
                                  self.vio, 
                                  self.pre, self.logger)
 
        window.create_widget()
        window.show()
        app.exec_()

Tried method
#       app.close()
#        for widget in appl.allwidgest():
#           widget.close
      

Upvotes: 0

Views: 653

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

If you want to terminate the application then you must use the quit() method:

QCoreApplication.quit()

If instead you want to close all the windows then there are the following options:

  1. Close all toplevel widgets:

    for tl_widget in QApplication.topLevelWidgets():
        tl_widget.close()
    
  2. Close all QWindows

    for window in QGuiApplication.topLevelWindows():
        window.close()
    

Upvotes: 1

Related Questions