首页 > 解决方案 > 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(使用上述命令行构建)。现在我的部署问题是:

我尝试阅读几篇 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

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

标签: qt

解决方案


问题在于默认情况下不支持 OpenGL 的 VirtualBox 显示驱动程序。当我在 VirtualBox 设置中打开 3D 加速时,Qt Qml 静态应用程序工作。这也证明了为什么我的静态链接应用程序可以在 Windows 10 上运行,因为这些应用程序安装在直接硬件上,而不是 VM 上,因此使用了适当的底层驱动程序和 opengl。

因此,这意味着当您使用-opengl desktop标志时,它使用底层操作系统的 opengl 库,即使 mingw 与 -lopenglw32 链接,它仍然依赖于系统的 opengl。


推荐阅读