How to view source of HTML in QWebView ?
-
wrote on 12 Aug 2017, 08:31 last edited by sonichy 8 Dec 2017, 08:51
void MainWindow::viewSource()
{
QString s = ui->webView->page()->currentFrame()->toHtml();
QUrl url = ui->webView->url();
ui->webView->setHtml(s,url);
}
It has no effort. -
void MainWindow::viewSource()
{
QString s = ui->webView->page()->currentFrame()->toHtml();
QUrl url = ui->webView->url();
ui->webView->setHtml(s,url);
}
It has no effort.@sonichy Take a look at https://stackoverflow.com/questions/16783708/how-to-display-raw-html-code-in-pre-or-something-like-it-but-without-escaping-it
You need to prevent the HTML source code from being interpreted as HTML, so you need to create a new HTML string where you put your HTML source into <pre></pre>. -
@sonichy Take a look at https://stackoverflow.com/questions/16783708/how-to-display-raw-html-code-in-pre-or-something-like-it-but-without-escaping-it
You need to prevent the HTML source code from being interpreted as HTML, so you need to create a new HTML string where you put your HTML source into <pre></pre>.wrote on 18 Aug 2017, 04:55 last edited byI find the solution: change "<" to "<" and ">" to ">" before use <pre>. QString s = ((QWebView*)(ui->tabWidget->currentWidget()))->page()->currentFrame()->toHtml(); s=s.replace("<", "<"); s=s.replace(">", ">"); s="<title>source</title><pre>"+s+"</pre>"; QUrl url = ((QWebView*)(ui->tabWidget->currentWidget()))->url(); newTab(); ((QWebView*)(ui->tabWidget->currentWidget()))->setHtml(s,url);
1/3