PDA

View Full Version : WebKit: mainFrame()->load(url) in a for loop



ouekah
3rd March 2010, 19:55
Hi,

i would like to download sequentially an unknown number of webpages. So I naturally thought of using a for loop to achieve that.

But the problem is that mainFrame()->load(url) doesn't wait if a previous load was already running for the same QWebPage object. As a consequence the previous download is interrupted and the signal loadFinished is emitted, but when the corresponding slot is executed it appears naturally that the content of the previous webpage is almost empty (at least the information I need is not available...).

At the end of the for loop, only the last download successfully achieves (probably because it is not interrupted...).

I could handle this using a global boolean :o, but I was wondering if there was a more elegant way to perform what I want using the Qt framework.

Any ideas ?

prof.ebral
3rd March 2010, 21:02
http://doc.qt.nokia.com/4.6/qwebpage.html#loadFinished

Sorry, just reread your post and noticed that you mentioned the loadFinished signal.

Be sure to check out: http://doc.qt.nokia.com/4.6/qwebpage.html#loadProgress also. You could wait for the load while the loadProgress != 100

ouekah
4th March 2010, 10:35
I wouldn't post a thread if I didn't read the official documentation first.

Your answer doesn't help me at all...

Forget it I'll use my boolean idea.

ouekah
4th March 2010, 12:21
Well my boolean trick didn't work.

I had to use the loadFinished signal instead... not very intuitive...

rbp
20th September 2010, 07:42
did you come up with a more elegant solution?

wysota
20th September 2010, 09:28
Using loadFinished() is the proper solution. Of course if you really need WebKit and can't live with pure QNetworkAccessManager.

rbp
20th September 2010, 12:52
usually yes, but for current project I use webkit to automate navigating deep into a javascript powered website, and the logic would be simpler if I could block while loading the HTML.

Is there a cleaner way to block than:

loaded = false; // set to true in loadFinished()
load(url);
while(!loaded) {
// wait
}
// process html

wysota
20th September 2010, 13:12
Of course.
Waiting in a local event loop (http://doc.trolltech.com/qq/qq27-responsive-guis.html#waitinginalocaleventloop)

rbp
20th September 2010, 13:45
QEventLoop (http://doc.trolltech.com/4.6/qeventloop.html) - brilliant!