QWebEngineView 使用时,加载本地的html页面 出现白屏,并且QWebEngineView没有收到loadProgress 信号,在其他电脑没问题,html网页没有问题
代码如下;
#include <QApplication>
#include <QtWidgets>
#include <QTextBrowser>
#include <QtWebEngineWidgets>
#include <QGuiApplication>
#include <QDialog>
#include <QProcessEnvironment>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 创建主窗口
QDialog window;
window.setWindowTitle("交易要素信息");
window.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
// 设置窗口大小和位置
int width = 64 * 12;
int height = 42 * 12;
QRect desktopRect = QGuiApplication::screens().at(0)->availableGeometry(); // 使用 QGuiApplication 获取屏幕几何形状
window.setGeometry(desktopRect.width() - width, desktopRect.height() - height, width, height);
// 加载本地 HTML 文件
QString htmlFilePath = "index.html";
QUrl url = QUrl::fromLocalFile(htmlFilePath);
QWebEngineView view(&window);
view.load(url);
QObject::connect(&view, &QWebEngineView::loadProgress, [](int progress) {
qDebug() << "Loading progress:" << progress;
});
QObject::connect(&view, &QWebEngineView::loadFinished, [](bool ok) {
qDebug() << "Loading finished:" << ok;
});
// 将 QWebEngineView 添加到主窗口中
QVBoxLayout layout(&window);
layout.addWidget(&view);
// 设置窗口固定大小
window.setFixedSize(width, height);
window.setWindowFlag(Qt::MSWindowsFixedSizeDialogHint);
// 显示主窗口
window.show();
//window.close();
return a.exec();
}
运行时日志:
QML debugging is enabled. Only use this in a safe environment.
qt.webenginecontext:
GL Type: desktop
Surface Type: OpenGL
Surface Profile: NoProfile
Surface Version: 3.2
QSG RHI Backend: OpenGL
Using Supported QSG Backend: yes
Using Software Dynamic GL: no
Using Multithreaded OpenGL: no
Init Parameters:
* application-name showHtml
* browser-subprocess-path /home/ChenDong/qt/qtSetApp/6.3.2/gcc_64/libexec/QtWebEngineProcess
* disable-features ConsolidatedMovementXY,InstalledApp,BackgroundFetch,WebOTP,WebPayments,WebUSB,PictureInPicture
* disable-setuid-sandbox
* disable-speech-api
* enable-features NetworkServiceInProcess,TracingServiceInProcess
* enable-threaded-compositing
* enable-use-zoom-for-dsf false
* in-process-gpu
* use-gl desktop
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/016613934186114.png "#left")