Results 1 to 12 of 12

Thread: Using QWebElement.findAll() without using QWebFrame and its parent classes

  1. #1
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Using QWebElement.findAll() without using QWebFrame and its parent classes

    Hello all,

    I wonder if there is any alternative to using QWebElement.findAll() without setting up classes up to QWebPage ? Because in my case this causes immense resource consumption from 7MB up to 21MB (also WebCoreNode leak warning) just to create a virtual webpage of nonvisible html code - but I have to admit I did only page.deleteLater(); to manage resources. Here is the code:
    Reply is QNetworkReply
    Qt Code:
    1. QWebPage page;
    2. QWebFrame *frame = page.mainFrame();
    3. QString htmlReply = Reply->readAll();
    4. frame->setHtml(htmlReply);
    5. QWebElement html = frame->documentElement();
    6. QWebElementCollection myOutput = html.findAll("DIV.myClass");
    To copy to clipboard, switch view to plain text mode 
    Or do I have to use regexp search on qstring with html code?

    Thanks for any answers

  2. #2
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Hello again, since nobody replied to this thread I must've missed some obvious facts or I formulated my post unclearly. I already gave up searching for alternatives to QWebPage DOM, so I would like to proceed with one more question.

    Now I would like to ask a more clear question: Why does frame->setHtml(htmlReply); cause heavy resource consumption? I tracked down that at this point the memory usage (reported by task manager) went from ~5MB to ~19MB and it stayed that way until the program was terminated (I used deleteLater() on frame, but with no effect). Btw htmlReply contained only 10322 bytes of html page.

    I would be happy if someone would care to explain this to me,

    Thanks again

  3. #3
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Nobody ? Still got the same issue - spike in memory usage and WebCoreNode leak message after program ends, code is almost the same:
    Qt Code:
    1. void MainWindow::replyFinished(QNetworkReply *reply)
    2. {
    3. QWebPage page;
    4. QWebFrame *frame = page.mainFrame();
    5.  
    6. QByteArray html = reply->peek(reply->size()); //~10kB
    7. frame->setContent(html);
    8. QWebElement htmlElement = frame->documentElement();
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    I do this only for the access to html element contents, page is not showed visually anywhere.
    Last edited by ntXn; 14th April 2013 at 14:06.

  4. #4
    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: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Well... obviously setting content on a frame causes it to be parsed and filled with webpage data, hence memory consumption. The size of the webpage source code does not correspond to memory size consumed by the webpage, if that's what you expected.

    If you wish to work on the page source only then don't use WebKit but rather parse the code using XML parsers or regular expressions.
    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.


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

    ntXn (14th April 2013)

  6. #5
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Thanks! That's what I wanted to know. Seems like I have no other options, regular expressions would be too impractical in my case, and XML parsers are not able to parse HTML as it's said here http://stackoverflow.com/a/5202694

    So now my only remaining problem is to solve the WebCoreNode leak, any ideas how ? I tried deleteLater() on everything, didn't help. WebCoreNode leak warning shows only when I include the abovementioned code, so the root cause should be there.

  7. #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: Using QWebElement.findAll() without using QWebFrame and its parent classes

    I have no idea what leak you are talking about.
    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.


  8. #7
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Well, I get this in qt creator console "LEAK: x WebCoreNode" message when I exit my program. x is a random number
    Attached Images Attached Images

  9. #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: Using QWebElement.findAll() without using QWebFrame and its parent classes

    And where does this message come from?
    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.


  10. #9
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    What I know is that the leak happens when I use the WebKit in my function replyFinished() - check my previous posts please, I don't want to repost the same code again.

    Thanks

  11. #10
    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: Using QWebElement.findAll() without using QWebFrame and its parent classes

    How do you know there is any leak? You only get some warning from some undetermined component.
    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.


  12. #11
    Join Date
    Mar 2013
    Location
    Slovakia
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Oh, so that shouldn't bother me ? Ok then, I can say that my program runs normally I was just scared, because I know that memleaks should be solved.

  13. #12
    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: Using QWebElement.findAll() without using QWebFrame and its parent classes

    Quote Originally Posted by ntXn View Post
    Oh, so that shouldn't bother me ?
    I don't know if it should bother you or not. Without investigating, it is just some message. That's why I asked you where the message comes from and I didn't mean your code but rather what generates this message.
    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.


Similar Threads

  1. Set html <style> with QWebElement
    By poser in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2014, 17:31
  2. How to use a public Qwebelement variable
    By luisvt in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2012, 10:22
  3. QWebElement render problem
    By Vaterland in forum Qt Programming
    Replies: 0
    Last Post: 23rd March 2012, 23:36
  4. QWebElement evaluateJavaScript problem
    By Talei in forum Newbie
    Replies: 0
    Last Post: 10th March 2011, 04:38
  5. Dynamically create SVG with QWebElement
    By yawar in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2010, 03:53

Tags for this Thread

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.