[Qtwebengine] QWebEnginePage.toHtml hangs indefinitely

Kevin Truong knt261 at gmail.com
Fri Jan 8 01:49:23 CET 2016


Nevermind, found the bug. In case anyone else has the same problem in the
future: there was data being posted to stdin, but my program never read
from it, so I guess the text stream was hanging indefinitely waiting for a
program to read the data from stdin.

On Wed, Jan 6, 2016 at 4:55 PM, Kevin Truong <knt261 at gmail.com> wrote:

> 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/20160107/6beb0741/attachment.html>


More information about the QtWebEngine mailing list