qt - Qt 静态应用程序无法在已部署的系统上运行
问题描述
在 Linux 上成功构建静态 QT 和我的应用程序二进制文件后,我移至 Windows 进行了同样的尝试。
..\qt-everywhere-src-5.12.8\configure.bat -opensource -confirm-license -release -static -static-runtime -no-pch -optimize-size -opengl desktop -platform win32-g++ -prefix "C:\Qt\Static" -skip webengine -nomake tools -nomake tests -nomake examples
mingw32-make -j4 && mingw32-make install
我的开发环境是 Windows 10 x64、MinGW 7.3.0、QT 5.12.8 Static(使用上述命令行构建)。现在我的部署问题是:
- 奇怪的是,该二进制文件在 Windows 10 的新副本上运行,但不在 Windows 7 上。更令人惊讶的是,我尝试在 Linux Wine 上运行该二进制文件,瞧,它也在那里工作。
- 另一个问题与自定义字体加载有关,即
QFontDatabase::addApplicationFont
在 Windows 静态构建上也失败。而相同的代码在 Linux 静态构建或 Windows 动态 QT 链接上运行良好。我根据一些stackoverflow帖子进行了尝试Q_INIT_RESOURCE
,但这没有帮助。
我尝试阅读几篇 qt wiki 文章,但到目前为止,对于上述两个问题都没有任何帮助。
编辑#1
这是静态构建失败的字体加载代码:
Q_INIT_RESOURCE(qml);
int idFont = QFontDatabase::addApplicationFont(":/fonts/Comfortaa-Bold.ttf");
if (idFont == -1)
{
qDebug() <<"Failed to load font from resource";
....
编辑#2
有一个新的希望。我刚刚尝试构建一个简单的小部件应用程序并使用相同的 Qt 版本静态构建它。现在它可以在新的 Windows 7 上运行。所以我需要弄清楚为什么 QML 应用程序不起作用。在 Qt 静态构建期间,我是否需要为 qml 模块或插件做任何特定的事情?
编辑#3
- 通过更改 VM 设置修复了 Windows 7 执行问题。
- 通过重建 Qt 修复了字体加载问题。这次我使用了 Qt 5.15.0,命令行是:
configure.bat -opensource -confirm-license -prefix "C:\Qt\5.15.0-Static" -release -static -static-runtime -opengl desktop -platform win32-g++ -make libs -qt-libpng -qt-libjpeg -qt-freetype -qt-zlib -nomake tools -nomake examples -nomake tests -skip qttools
解决方案
问题在于默认情况下不支持 OpenGL 的 VirtualBox 显示驱动程序。当我在 VirtualBox 设置中打开 3D 加速时,Qt Qml 静态应用程序工作。这也证明了为什么我的静态链接应用程序可以在 Windows 10 上运行,因为这些应用程序安装在直接硬件上,而不是 VM 上,因此使用了适当的底层驱动程序和 opengl。
因此,这意味着当您使用-opengl desktop
标志时,它使用底层操作系统的 opengl 库,即使 mingw 与 -lopenglw32 链接,它仍然依赖于系统的 opengl。
推荐阅读
- laravel - Laravel: 方法 ...Controller::show 不存在
- android - 如何修复 ionic 3 中的 Typescript 错误?索引.d.ts
- xcode - @Published ObservedObjects SwiftUI 更新未发生
- c++ - 如何从 _clicked() 事件中发出另一个实例的信号?
- google-cloud-firestore - Firestore简单的collectionGroup使函数超时
- git - 为 Git Bash 配置代理凭据,但面临特殊字符问题
- reactjs - 使用 Docker-Compose 为 React 和 Flask 配置 Nginx
- java - 方法调用失败 JAX-RS / Wildfly / Java SDK13 带拦截器
- html - 表格列宽问题
- c# - BlockingCollection 是线程安全的吗?