Results 1 to 7 of 7

Thread: Unwanted downloads with QWebPage/QWebPage

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

    Default Unwanted downloads with QWebPage/QWebPage

    Hi,

    I use two QWebPage objects to download two webpages and the loadFinished(bool) signal of these pages is connected to one slot pageDownloaded(bool).

    But it appears that one of these pages (not always the same) is downloaded twice ! Here is my code:


    Qt Code:
    1. void main() {
    2. QWebPage page1;
    3. QWebPage page2;
    4. connect(&page1, SIGNAL(loadFinished(bool)), this, SLOT(pageDownloaded(bool)));
    5. connect(&page2, SIGNAL(loadFinished(bool)), this, SLOT(pageDownloaded(bool)));
    6. QString url1 = "http://www.google.com";
    7. QString url2 = "http://www.yahoo.com";
    8. page1.mainFrame()->load(QUrl(url1));
    9. qWarning() << "downloading page 1";
    10. page2.mainFrame()->load(QUrl(url1));
    11. qWarning() << "downloading page 2";
    12. }
    13. ...
    14. void pageDownloaded(bool ok) {
    15. qWarning() << "page downloaded";
    16. }
    To copy to clipboard, switch view to plain text mode 

    does anybody know how to avoid that situation ?

  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unwanted downloads with QWebPage/QWebPage

    But it appears that one of these pages (not always the same) is downloaded twice
    Sorry, I'm not clear about what exactly is happening-

    Are you getting two copies of the same page, both pages plus an additional copy of one of them, both pages but 3 'page downloaded' messages or what?

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unwanted downloads with QWebPage/QWebPage

    Well, both pages are using url1, so it's natural to accept that the same page will be downloaded twice...

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

    Default Re: Unwanted downloads with QWebPage/QWebPage

    Sorry wrong copy/paste... no it's url2...

    what happens exactly is that pageDownloaded(bool) is executed more than two times which for me means that a page has been downloaded more than once.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Unwanted downloads with QWebPage/QWebPage

    Maybe it's working as normal. For example, what happens if you request www.google.com, and the website decides to redirect you to a different server to handle that request? Then you would download 2 web pages, a redirect and the actual page.

    You should change your code so you can tell the pages apart, and then display the number of bytes downloaded by each page. If one of the pages show two different sizes, then this is probably whats happening.

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

    Default Re: Unwanted downloads with QWebPage/QWebPage

    I need to parse web pages to extract some data and I would like to use QtXml to do that. My initial idea was to use a QNetworkReply in conjunction with QDomDocument::setContent.

    But unfortunately html pages are not necessarily well formed xml documents, so this doesn't work.

    So I used QWebPage instead because it provides functionality to parse html page directly. But now I have the following problem: when I download a webpage (QWebPage::mainFrame()->load(QUrl())), the QWebPage::loadFinished() signal may be emitted several times which generates errors in my application. Frankly speaking I don't know what happens, but I don't think that it's redirection (I've been on this pages and their URL does not change).

    Now I think that I should maybe rather use a simple QNetworkManager to do what I want.

    But is there a way to convert text in html format into text in xml format using Qt ? This should hopefully solve my problem.

  7. #7
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Unwanted downloads with QWebPage/QWebPage

    Maybe this is not the best help You cant get, but first: why don't qDebug() << incomingdata; ? Dump the data in each reply and see for Yourself what's going on.
    Alternatively, if you don't want rewrite/write code, use sniffing tool, i.e. Wireshark, don't download anything (that way less output in Wireshark hence nicer work) and run sniffer/Your program and see What Really is going on.

Similar Threads

  1. QWebPage error handling
    By Guilo in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2010, 05:48
  2. How to use qwebpage in non-gui app
    By Cykus in forum Newbie
    Replies: 4
    Last Post: 10th May 2010, 11:35
  3. Get images from a QWebView or QWebPage
    By redneon in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2010, 09:03
  4. Can QWebPage see changes in a website
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 15th August 2009, 23:23
  5. QwebPage within a QGraphicsWidget
    By Osprey in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 17:32

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.