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.

    experiment_widget.cpp

    #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) :
        QMainWindow(parent),
        ui(new Ui::experiment_widget),
        web_page_(nullptr),
        web_view_(new QWebEngineView(this))
    {
        ui->setupUi(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
        //web_page_->load(QUrl("https://www.bing.com/images/search?q=smoke"));
        web_view_->load(QUrl("https://www.bing.com/images/search?q=smoke"));
    }
    
    experiment_widget::~experiment_widget()
    {
        delete ui;
    }
    
    void experiment_widget::web_page_load_finished(bool ok)
    {
        qDebug()<<"web page load finished:"<<ok;
        parse_image_link();
    }
    
    void experiment_widget::web_view_load_finished(bool ok)
    {
        qDebug()<<"web view load finished:"<<ok;    
        parse_image_link();
    }
    
    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.