日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

QT 调用QWebEngineView显示网页

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

環境:

  • Windows:10
  • C++ Qt:5.14.1

步驟:
第一步:需要在 xxxxx.pro 下添加 QT += webenginewidgets
第二步:mainwindow.h中添加 QWebEngineView 屬性
第三步:mainwindow.cpp 中創建 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); // 設置窗口大小setWebview(); }void MainWindow::setWebview(){view->page()->load(QUrl("http://www.baidu.com")); //打開百度view->show(); // 顯示視圖}MainWindow::~MainWindow(){delete ui; }

運行結果:

總結

以上是生活随笔為你收集整理的QT 调用QWebEngineView显示网页的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。