webkit的基本应用
新建Qt Widgets Application->Browser01
修改.pro文件内容:
#------------------------------------------------- # # Project created by QtCreator 2015-08-24T21:48:01 # #------------------------------------------------- QT += core gui QT +=webkitwidgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Browser01 TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
界面:
mainwindow.cpp内容
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { ui->webView->back(); } void MainWindow::on_pushButton_2_clicked() { ui->webView->forward(); } void MainWindow::on_pushButton_3_clicked() { ui->webView->reload(); } void MainWindow::on_pushButton_4_clicked() { ui->webView->load("http://"+ui->lineEdit->text()); } void MainWindow::on_lineEdit_returnPressed() { on_pushButton_4_clicked(); }