日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

QT 调用QWebEngineView显示网页

發(fā)布時間:2025/5/22 c/c++ 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 QT 调用QWebEngineView显示网页 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

環(huán)境:

  • Windows:10
  • C++ Qt:5.14.1

步驟:
第一步:需要在 xxxxx.pro 下添加 QT += webenginewidgets
第二步:mainwindow.h中添加 QWebEngineView 屬性
第三步:mainwindow.cpp 中創(chuàng)建 QWebEngineView 對象,并使用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 += target

mainwindow.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_H

main.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显示网页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。