Important: Please read the Qt Code of Conduct -

toHtml of QWebEnginePage always return empty string

  • os : win 10 64bits
    compiler : visual c++ 205
    Qt version : Qt5.8, Qt5.9 beta 3

    I search the solution on stackOverflow but none of them work.


    #include "experiment_widget.hpp"
    #include "ui_experiment_widget.h"
    #include <QDebug>
    #include <QRegularExpression>
    #include <QRegularExpressionMatch>
    #include <QWebEnginePage>
    #include <QWebEngineView>
    experiment_widget::experiment_widget(QWidget *parent) :
        ui(new Ui::experiment_widget),
        web_view_(new QWebEngineView(this))
        ui->gridLayout->addWidget(web_view_, 3, 0, 1, 2);
        connect(web_view_, &QWebEngineView::loadFinished, this, &experiment_widget::web_view_load_finished);    
        web_page_ = web_view_->page();
        connect(web_page_, &QWebEnginePage::loadFinished, this, &experiment_widget::web_page_load_finished);
        //load by webpage do not work either
        delete ui;
    void experiment_widget::web_page_load_finished(bool ok)
        qDebug()<<"web page load finished:"<<ok;
    void experiment_widget::web_view_load_finished(bool ok)
        qDebug()<<"web view load finished:"<<ok;    
    void experiment_widget::parse_image_link()
        web_page_->toHtml([this](QString const &contents)
            qDebug()<<"get image link contents";
            qDebug()<<contents; //always empty        

    toPlainText work, but what I want is the source codes of the page.

    Whole project is place at mega.

  • I give it a try under ubuntu16.04.1, it works. I guess this is a bug of Qt and open an issue

  • Open bug report, ticket is 60669

  • @tham
    This is a bit of a necro, but for anyone coming across this I believe this is not a bug but is addressed by understanding & following

Log in to reply