Unsolved How to close the application correctly?
-
The purpose of code below is download the source code and close it self, but, the program self close before download the source code. What I'm doing wrong?
import re import sys import time from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets, QtWebEngineCore, QtWebEngine from PyQt5.QtWebEngineWidgets import * class Widget(QtWidgets.QWidget): def __init__(self): self.url = "https://www.linkedin.com" super(Widget, self).__init__() lay = QtWidgets.QVBoxLayout(self) self.browser = QtWebEngineWidgets.QWebEngineView() lay.addWidget(self.browser) self.browser.setUrl(QtCore.QUrl(self.url)) self.browser.loadFinished.connect(self.load_finished_handler) @QtCore.pyqtSlot() def load_finished_handler(self): global app # SingleHtmlSaveFormat # CompleteHtmlSaveFormat self.browser.page().save( r'C:/Users/User/Desktop/web.html', format=QWebEngineDownloadItem.SingleHtmlSaveFormat ) app.exit(0) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) view = Widget() view.show() #app.exec_() sys.exit(app.exec_())
-
Hi,
Does it work if you don't call
app.exit(0)
? -
@SGaist But I need download the HTML source code and close the main app function... I've put the "app.exit(0)" after the save() to close after download the HTML.
-
void QWebEnginePage::save()
This function issues an asynchronous download request for the web page and returns immediately.