QWebView - main GUI thread stops to respond after trying to load a page
-
You don't need an eventloop to do that. Just connect your robots startWork function to the loadFinished signal. The timeout signal could be connected to a tryReload function or a loadNextPage function.
I'm noticing you're using python. I'm not sure if connect for signals and slots is available there, but since it's such a crucial feature of Qt it most certainly is.
-
do you mean that I do not need an eventloop to wait for the page to finish loading ?
-
Sometimes event loop loops infinitely when using network requests (I don't know why tho). Therefore I suggest to use event loop "manually" to process events as long as you are really need to.
@
SomeProcess process;
process.start();QEventLoop loop;
while (process.isRunning())
loop.processEvents();process.getResults();
@ -
before I started using QEventLoop, I manualy processed events using QApplication.processEvents(), that made the same bug, GUI thread hangs...
So I tried QEventLoop, but same bug happened.
You think eventloop.processEvents is different ? -
[quote author="NirBlinder" date="1371026555"]do you mean that I do not need an eventloop to wait for the page to finish loading ?[/quote]
You don't need an extra eventloop. Your application (QApplication or QCoreApplication) already has a running eventloop, so there's no need for a second one. You don't need to wait synchronously for the signal loadFinished. Just connect to the loadFinished signal and thats it.
Maybe I'm missing something, but from the use case you described there's no need for the extra degree of complexity you're adding with the second eventloop or the processEvent calls.
-
That is interesting , as I remember if I dump the eventloop, the webpage doesn't build itself, items are not painted at all, but maybe I am doing something wrong... ?
-
My application is currently running in main thread of GUI application.
its constructor looks something like this:@class MyBrowser(QApplication):
def init(self):
super(MyBrowser, self).init(None)
self.webView = QWebView()
self.page = WebPage(self.webView)
self.page.setUserAgent()
self.webView.setPage(self.page)
self.timer = QTimer()
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.timerTimeout)
self.timeoutReached = False
self.webView.showMaximized()
self.readyState = False
self.webView.loadFinished.connect(self.loadFinished)
self.eloop = QEventLoop()@and what I do is creating an instance of it:
@myBrowser = MyBrowser()@
and then something like:
@myBrowser.load("http://www,google.com")
myBrowser.waitLoad(60)
myBrowser.load(someotherpage)
myBrowser.someCustomFunction()@
and so on...So I do not use
@myBrowser.exec()@because there is no real user handling the browser.
Is that understood ?
Is that the right approach ? -
Ah ok so thats why you have no running eventloop and thus add your own.
Since I haven't used Qt with Python I can't really comment on that, but from the c++ perspective it seems weird. Maybe you should post a question in the "Language Bindings subsection ":http://qt-project.org/forums/viewforum/15/ of this forum. -
Ok thank you anyway , I will try that .
Maybe I will switch to QT with C++, I heard its more stable.Thank you for the help , I appreciate it.