http://opensource.spotify.com/cefbuilds/index.html#windows64_builds(Standard Distribution)
https://github.com/tishion/QCefView(efc4c55)
https://tishion.github.io/QCefView/
总结起来分下面几个步骤:
cmake生成vs2017工程,打开cef.sln,分别使用debug和release生成解决方案,生成后提示ceftests工程生成失败可忽略
将工程修改成vs2017环境,设置本地Qt版本号,编译、生成、运行过程中出现以下错误
最新的libcef只需要2个参数,修改成
return registrar->AddCustomScheme(scheme_name, false);
项目属性->调试->环境中添加$(SolutionDir)QCefViewSDK\bin\Debug
单步调试发现,在QCefView项目中CCefSetting.cpp第42行当这句话步过时就会崩溃
写个简单的测试
调试发现str_std离开大括号作用域程序立即崩溃,在Qt官方的bugreports寻找答案,看到有人提出过类似的问题 https://bugreports.qt.io/browse/QTBUG-63274,官方貌似说这不是bug,是编译器造成的,去Microsoft官方文档找答案(笑)。没办法不使用toStdString,换种写法避免这个问题,将QCefView工程中所有使用toStdString的地方(一共18处)换成toLocal8Bit,并使用std::string构造,例如
browser_sub_process_path.FromString(
std::string(QDir::toNativeSeparators(strExePath).toLocal8Bit()));
没有找到icu数据文件,将resources文件夹下的icudtl.dat拷贝到QCefViewSDK\bin\Debug目录下,并将resources整个文件夹拷贝到QCefViewTest项目下,QCefViewSDK\bin\Debug下的qtcefwing.exe也拷贝到QCefViewTest项目下,不然会出现渲染错误
将libcef目录下cef_binary_74.1.16+ge20b240+chromium-74.0.3729.131_windows64\tests\cefsimple中的cefsimple.exe.manifest和compatibility.manifest拷贝到QCefView和qtcefwing两个工程目录下,并将QCefView项目中的cefsimple.exe.manifest重命名为QCefView.dll.manifest,将qtcefwing项目中的cefsimple.exe.manifest重命名为qtcefwing.exe.manifest,设置QCefView项目的生成后事件,属性->生成事件->生成后事件->命令行中在xcopy命令前加入以下代码:
setlocal
mt.exe -nologo -manifest "compatibility.manifest" "QCefView.dll.manifest" -outputresource:"$(OutDir)QCefView.dll";#2
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
设置qtcefwing项目的生成后事件,属性->生成事件->生成后事件->命令行中加入以下代码:
setlocal
mt.exe -nologo -manifest "compatibility.manifest" "qtcefwing.exe.manifest" -outputresource:"$(OutDir)qtcefwing.exe";#1
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
重新生成解决方案,生成完后,重新将qtcefwing.exe拷贝到QCefViewTest项目中
文件路径不对,修改qcefviewtest.cpp中cefview创建时传入的文件路径
QDir dir = QDir::current();
QString uri = QDir::toNativeSeparators(dir.filePath("QCefViewTestPage.html"));
cefview = new CustomCefView(uri/*"http://www.sina.com"*/, this);
这个貌似是代理造成的,release下不会出现这个问题,debug下有两种选择,不使用或者使用全局代理(应用程序也能上梯子)
下载修改后的工程