简体   繁体   中英

Quit PyQt4 app when loadFinished complete

I want to close the window after loadFinished complete. imagine simple code:

class Example(QWebView):
    def __init__(self):
        QWebView.__init__(self)
        self.frame = self.page().mainFrame()
        self.frame.loadFinished.connect(self.some_action)

    def some_action(self):
        # do something here
        # after it's done close app

if __name__ == '__main__':
    app = QApplication(sys.argv)
    url = QUrl("some_website")
    br = Example()
    br.load(url)
    br.show()
    app.exec_()

Just call close() on the main window:

def some_action(self):
    # do something here
    # after it's done close app
    self.close()

Once the last primary window is closed, the application will automatically quit.

You could also just call the application's quit function directly:

    app.quit()

or, more generally:

    QCoreApplication.instance().quit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM