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
Forum Updated to NodeBB v4.3 + New Features

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.
  • T Offline
    T Offline
    tham
    wrote on 8 May 2017, 08:48 last edited by tham 5 Aug 2017, 19:20
    #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.

    T 1 Reply Last reply 8 May 2017, 20:09
    0
    • T tham
      8 May 2017, 08:48

      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.

      T Offline
      T Offline
      tham
      wrote on 8 May 2017, 20:09 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
      • T Offline
        T Offline
        tham
        wrote on 8 May 2017, 20:13 last edited by
        #3

        Open bug report, ticket is 60669

        J 1 Reply Last reply 5 Feb 2018, 12:41
        1
        • T tham
          8 May 2017, 20:13

          Open bug report, ticket is 60669

          J Offline
          J Offline
          JonB
          wrote on 5 Feb 2018, 12:41 last edited by JonB 2 May 2018, 12:41
          #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