toHtml of QWebEnginePage always return empty string
Unsolved
General and Desktop
-
os : win 10 64bits
compiler : visual c++ 205
Qt version : Qt5.8, Qt5.9 beta 3I 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.
-
@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