QT29 how to use QWebView and open web page in QWebView

for qt 5 or above

1. modify pro file

#-------------------------------------------------
#
# Project created by QtCreator 2016-03-30T20:04:00
#
#-------------------------------------------------

QT       += core gui webkitwidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = website
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

2. modify mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebKitWidgets/QWebView>
#include <QUrl>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->webView->load(QUrl("http://www.google.com"));
}



MainWindow::~MainWindow()
{
    delete ui;
}

QT29 how to use QWebView and open web page in QWebView_第1张图片


你可能感兴趣的:(QT29 how to use QWebView and open web page in QWebView)