解决qtwebenginview load崩溃问题,需要在main函数中添加上
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts ); //这句相当于QtWebEngine::initialize()
代码如下:
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts );
QGuiApplication app(argc, argv);
QWebEngineView *pView = new QWebEngineView();
pView->load("http://www.baidu.com");
return app.exec();
}
同时,使用了QWebEngineView的程序需要打安装包,最好是用qt自带的打包工具,windeployqt.exe,如命令:
C:\Qt\Qt5.12.11\5.12.11\mingw73_32\bin\windeployqt.exe -release D:/work/software.exe
会自动将所有qwebengineview所需要的动态库,插件自动放到你的运行目录下, 省去手动找和漏掉的问题