QtWebKit QApplication call twice
I am calling a scraping class from Flask and the second time I instantiate a new Webkit() class (QApplication), it exits my Flask app.
How can I re-run a Qt GUI app multiple times and have it contained so it does not shut down the "outer" app?
Further clarification, Qt is event drive and calling QApplication.quit() closes not only the event loop but Python as well. Not calling quit() though never continues executing the rest of the code.
class Webkit(): ... def __run(self, url, method, dict=None): self.qapp = QApplication(sys.argv) # FAIL here the 2nd time round req = QNetworkRequest() req.setUrl(QUrl(url)) self.qweb = QWebView() self.qweb.setPage(self.Page()) self.qweb.loadFinished.connect(self.finished_loading) self.qweb.load(req) self.qapp.exec_() def finished_loading(self): self.qapp.quit()
The only (hacky!) solution so far is for me is to add this to the WebKit() class:
if __name__ == '__main__': ....
and then parse the result from the Flask app with this:
return os.popen('python webkit.py').read()