qt example

#include"mainwindow.h"

#include"ui_mainwindow.h"
#include<QWebFrame>
#include<QWebInspector>
MainWindow::MainWindow(QWidget*parent):
QMainWindow(parent),
ui(newUi::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
deleteui;
}
voidMainWindow::on_pushButton_clicked()
{
QStringurl="http://www.baidu.com";
//url="http://192.168.201.75/ttt";
QWebPage*page=ui->webView->page();
QWebSettings*opt=page->settings();
QWebInspector*inspector=newQWebInspector;
opt->setAttribute(QWebSettings::AutoLoadImages,false);
opt->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
inspector->setPage(page);
inspector->setVisible(true);
inspector->show();
ui->webView->setUrl(QUrl(url));
//ui->webView->load(QUrl(url));
}
voidMainWindow::on_webView_loadFinished(boolarg1)
{
QWebPage*page=ui->webView->page();
QWebSettings*opt=page->settings();
opt->setAttribute(QWebSettings::AutoLoadImages,false);
//QStringhtml=ui->webView->page()->mainFrame()->toHtml();
QStringhtml=page->mainFrame()->toHtml();
QStringjs="document.getElementsByTagName('html')[0].outerHTML";
html=ui->webView->page()->currentFrame()->evaluateJavaScript(js).toString();
ui->plainTextEdit->setPlainText(html);
}
 

你可能感兴趣的:(example)