PDA

View Full Version : Using QWebElement.findAll() without using QWebFrame and its parent classes



ntXn
22nd March 2013, 13:24
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


QWebPage page;
QWebFrame *frame = page.mainFrame();
QString htmlReply = Reply->readAll();
frame->setHtml(htmlReply);
QWebElement html = frame->documentElement();
QWebElementCollection myOutput = html.findAll("DIV.myClass");

Or do I have to use regexp search on qstring with html code?

Thanks for any answers

ntXn
25th March 2013, 12:06
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

ntXn
14th April 2013, 13:50
Nobody ? :( Still got the same issue - spike in memory usage and WebCoreNode leak message after program ends, code is almost the same:

void MainWindow::replyFinished(QNetworkReply *reply)
{
QWebPage page;
QWebFrame *frame = page.mainFrame();

QByteArray html = reply->peek(reply->size()); //~10kB
frame->setContent(html);
QWebElement htmlElement = frame->documentElement();
...
}
I do this only for the access to html element contents, page is not showed visually anywhere.

wysota
14th April 2013, 15:12
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.

ntXn
14th April 2013, 15:59
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.

wysota
14th April 2013, 16:09
I have no idea what leak you are talking about.

ntXn
14th April 2013, 16:19
Well, I get this in qt creator console "LEAK: x WebCoreNode" message when I exit my program. x is a random number

wysota
14th April 2013, 16:33
And where does this message come from?

ntXn
14th April 2013, 17:12
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

wysota
14th April 2013, 17:20
How do you know there is any leak? You only get some warning from some undetermined component.

ntXn
14th April 2013, 18:05
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.

wysota
14th April 2013, 19:54
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.