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()

Answers


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()

Need Your Help

What are some cool Javadoc doclet/templates?

java templates javadoc xdoclet doclet

I really don't like the way the default Javadocs look. I like the look of this one better. What are some other templates/doclets I can use for generating better JavaDoc pages?

How can I uninstall Win32 assemblies and cleanup WinSxS?

assemblies wix windows-installer uninstall winsxs

After a lot of trial and error (mostly due to lack of documentation and examples) I have managed to create MSI installers that install custom DLLs to WinSxS as side-by-side assembly. There is only ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.