Reputation: 904
I installed the newest version of Qt (on Webkit, Qt5.2 had WTFcrash). I try to get content of my website when the page is loaded (and it is):
QString sHtml;
view.page()->toHtml([&](const QString& result){sHtml = result;qDebug() << result;});
But sHtml
is empty, and debug not called. What am I doing wrong?
Upvotes: 6
Views: 4073
Reputation: 4125
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;
}
Upvotes: 4
Reputation: 904
Found it, toPlainText
work properly. Still don't know why toHtml doesn't.
Upvotes: 2