You're not doing anything wrong, you're just calling an asynchronous function :
Asynchronous method to retrieve the page's content as HTML, enclosed
in HTML and BODY tags. Upon successful completion, resultCallback is
called with the page's content.
The HTML won't be available directly after the call to toHtml()
. Instead, you can use some signals and slots to overcome this :
protected slots:
void handleHTML(QString sHTML);
signals:
void getHTML(QString sHTML);
void yourClass::yourFunction()
{
connect(this, SIGNAL(getHTML(QString)), this, SLOT(handleHTML(QString)));
view->page()->toHtml([this](const QString& result) mutable {emit getHTML(result);});
}
void yourClass::handleHTML(QString sHTML)
{
qDebug()<< "The HTML is :" << sHTML;
}
sHtml
went out of scope by the timetoHtml
was invoked. – Obstetrics