Results 1 to 9 of 9

Thread: WebKit: mainFrame()->load(url) in a for loop

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default WebKit: mainFrame()->load(url) in a for loop

    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 , but I was wondering if there was a more elegant way to perform what I want using the Qt framework.

    Any ideas ?

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    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

  3. #3
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    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.

  4. #4
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    Well my boolean trick didn't work.

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

  5. #5
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    did you come up with a more elegant solution?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    Using loadFinished() is the proper solution. Of course if you really need WebKit and can't live with pure QNetworkAccessManager.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    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:
    Qt Code:
    1. loaded = false; // set to true in loadFinished()
    2. load(url);
    3. while(!loaded) {
    4. // wait
    5. }
    6. // process html
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    rbp (20th September 2010)

  10. #9
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WebKit: mainFrame()->load(url) in a for loop

    QEventLoop - brilliant!

Similar Threads

  1. infinite loop
    By zakis in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2009, 18:52
  2. main loop
    By dusza in forum Qt Programming
    Replies: 10
    Last Post: 6th June 2009, 18:29
  3. while loop question..
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2009, 11:48
  4. Event Loop
    By node_ex in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2008, 08:52
  5. Load WebKit dll at run time
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2008, 10:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.