Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. toHtml of QWebEnginePage always return empty string

toHtml of QWebEnginePage always return empty string

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by tham
    #1

    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.

    thamT 1 Reply Last reply
    0
    • thamT tham

      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.

      thamT Offline
      thamT Offline
      tham
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • thamT Offline
        thamT Offline
        tham
        wrote on last edited by
        #3

        Open bug report, ticket is 60669

        JonBJ 1 Reply Last reply
        1
        • thamT tham

          Open bug report, ticket is 60669

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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 https://stackoverflow.com/questions/45363190/get-html-from-qwebenginepage-in-qwebengineview-using-lamda

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved