QT 调用QWebEngineView显示网页
生活随笔
收集整理的這篇文章主要介紹了
QT 调用QWebEngineView显示网页
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
環(huán)境:
- Windows:10
- C++ Qt:5.14.1
步驟:
第一步:需要在 xxxxx.pro 下添加 QT += webenginewidgets
第二步:mainwindow.h中添加 QWebEngineView 屬性
第三步:mainwindow.cpp 中創(chuàng)建 QWebEngineView 對(duì)象,并使用QWebEngineView 里的方法。
Use_QWebEngineView.pro
# 添加 webenginewidgets QT += core gui webenginewidgetsgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = web TEMPLATE = appCONFIG += c++11# The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \mainwindow.cppHEADERS += \mainwindow.hFORMS += \mainwindow.ui# Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += targetmainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H#include <QMainWindow> #include <QWebEngineView>QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACEclass MainWindow : public QMainWindow {Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();QWebEngineView *view;void setWebview();private:Ui::MainWindow *ui; }; #endif // MAINWINDOW_Hmain.cpp
#include "mainwindow.h" #include <QApplication>int main(int argc, char *argv[]){QApplication a(argc, argv);MainWindow w;w.show();return a.exec(); }mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){ui->setupUi(this);view = new QWebEngineView(this);view->resize(1920, 1080); // 設(shè)置窗口大小setWebview(); }void MainWindow::setWebview(){view->page()->load(QUrl("http://www.baidu.com")); //打開百度view->show(); // 顯示視圖}MainWindow::~MainWindow(){delete ui; }運(yùn)行結(jié)果:
總結(jié)
以上是生活随笔為你收集整理的QT 调用QWebEngineView显示网页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB reshape()函数和s
- 下一篇: MATLAB 循环子字符串