[Qtwebengine] QWebEnginePage.toHtml hangs indefinitely

Kevin Truong knt261 at gmail.com
Thu Jan 7 01:55:28 CET 2016


Hi community,

I am trying to use QWebEnginePage to render a page, then print the HTML of
that page when it finishes rendering. This is the slot I wrote to print out
the HTML of the page:

void Render::serialize() {
  m_page->toHtml([this](const QString &html) {
    std::cout << html.toStdString() << std::endl;
  });
}

However, there are some websites where this slot will hang indefinitely.
More specifically, I believe it is the html.toStdString() line that hangs,
because when I change the code to this:

void Render::serialize() {
  std::cout << "test1\n";
  m_page->toHtml([this](const QString &html) {
    std::cout << "test2\n";
    std::cout << html.toStdString() << std::endl;
    std::cout << "test3\n";
  });
}

Then "test1" and "test2" is printed, but "test3" was never printed (nor the
html).

The test URL that I used is a very slow to load website, where
loadFinished() never seems to be signaled. Is it because I called
html.toStdString() before loadFinished() signaled that this code hangs
indefinitely? If not, what other causes could it be?

I tried to find the answer myself by digging through the web engine code
and chromium code, and it seems like m_page->toHtml() sends an IPC message
to a render view observer host to fetch the document markup. I was
thinking, perhaps the render view observer host is busy with some other job
(e.g. its still trying to render the page until loadFinished()), and so
never handles the IPC message sent by m_page->toHtml(). I don't know much
about chromium, so I may be way off, but if this is true, is there a way I
can stop all current jobs by the render view observer host, so that it
handles the m_page.toHtml() document markup fetch message? I tried running
m_page->triggerAction(QWebEnginePage::WebAction::stop) right before
m_page.toHtml(), but to no success.

If you guys have any other ideas, I would be much appreciated to hear them!

Thanks,
Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qtwebengine/attachments/20160106/d12ecab2/attachment.html>


More information about the QtWebEngine mailing list