欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > Windows/Linux部署Qt并通过Qt Installer Framework制作安装包

Windows/Linux部署Qt并通过Qt Installer Framework制作安装包

2025/5/16 21:35:56 来源:https://blog.csdn.net/yihuajack/article/details/143482571  浏览:    关键词:Windows/Linux部署Qt并通过Qt Installer Framework制作安装包

本文参考 Qt Installer Framework Manual。
若要使用 Qt Installer Framework(简称 QIF),需要在 Qt Online Installer 或 Qt Maintenance Tool 中确保该组件已安装(QIF 组件在 Qt->Developer and Design Tools 下),否则需要先安装。
qif-install
安装好后可在 Qt 安装目录下确认是否有binarycreator可执行文件:

  • Windows:D:\Qt\Tools\QtInstallerFramework\4.8\bin\binarycreator.exe
  • Linux: /opt/Qt/Tools/QtInstallerFramework/4.8/bin/binarycreator

参考 Tutorial: Creating an Installer,以下进行 QIF 配置:
在部署目录下新建config目录,并在 config 目录下新建config.xml

<?xml version="1.0" encoding="UTF-8"?>
<Installer><Name>Your application</Name><Version>1.0.0</Version><Title>Your application Installer</Title><Publisher>Your vendor</Publisher><StartMenuDir>Super App</StartMenuDir><TargetDir>@HomeDir@/InstallationDirectory</TargetDir><ProductImages><ProductImage><Image>Logo.svg</Image><Url>https://xxx</Url></ProductImage></ProductImages>
</Installer>

在部署目录下新建package目录,并在 packages 目录下新建 com.vendor.product 目录,在该目录下新建data目录与meta目录,在 meta 目录下新建 packages.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package><DisplayName>The root component</DisplayName><Description>Install this example.</Description><Version>0.1.0-1</Version><ReleaseDate>2010-09-21</ReleaseDate><Licenses><License name="GNU General Public License v3.0" file="LICENSE" /></Licenses><Default>script</Default><Script>installscript.qs</Script><UserInterfaces><UserInterface>page.ui</UserInterface></UserInterfaces>
</Package>

如果包含了许可文件,则需要将许可文件复制到 meta 目录下,否则可以删去 Licenses 条目。Script 与 UserInterface 条目均为可选,用来定制安装引导程序的页面用户界面与相应操作,例如可以参考 Open ReadMe Example 在安装完成后的界面显示一个 Open README 选项。
open-readme
默认安装引导程序可以省略这两个条目。此外,如果希望为安装程序添加资源文件,可以在部署目录下新建resources目录,在该目录下新建additional.qrc定义资源文件。
QIF 配置完成后,在制作安装包之前,需要首先部署 Qt 项目。

Windows

对于 Windows 而言,部署较为简单,因为 Qt 为 Windows 平台提供了windeployqt工具,可在 D:\Qt\6.8.0\msvc2022_64\bin 下找到 windeployqt.exe。找到 Qt 项目的构建目录(对于 Qt Creator 而言默认目录名为build,对于 CLion 而言形如cmake-build-debug-visual-studio),将构建目录下的程序文件 MyApp.exe 复制到packages/com.vendor.product/data目录下,然后打开 Qt 6.8.0 (MSVC 2022 64-bit) 命令行,切换到构建目录下执行

windeployqt <path-to-app-binary>

或对于 Qt Quick 项目

windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>

例如

windeployqt --qmldir qml ..\deploy\packages\com.vendor.product\data

部署完成后,执行

D:\Qt\Tools\QtInstallerFramework\4.8\bin\binarycreator.exe  -c config/config.xml  -r resources/additional.qrc -p packages <App-Installer-Name>

即可制作安装包。

Linux

对于 Linux 而言 Qt 目前没有提供官方的部署工具,本文采用cqtdeployer工具,可通过sudo snap install cqtdeployer安装。注:安装snap后可选将/snap/bin添加到PATH环境变量。
假设 Qt 项目的构建目录为 ~/YourApp/build/Desktop_Qt_6_8_0-Debug,QML 目录为构建目录下的qml目录。安装完成后,可以通过cqtdeployer getDefaultTemplate qif获取默认 QIF 配置模板,其中只包含一个config.xml文件和一个contorlScript.qs文件。默认目标目录targetDirDistributionKit。我们也可以将我们自己的 QIF 配置放在部署目录下,然后执行

/snap/bin/cqtdeployer -bin ~/YourApp/build/Desktop_Qt_6_8_0-Debug -qmlDir ~/YourApp/build/Desktop_Qt_6_8_0-Debug/qml -qmake /opt/Qt/6.8.0/gcc_64/bin/qmake
/snap/bin/cqtdeployer -bin ~/DistributionKit/bin -qmlDir ~/DistributionKit/qml qif <path-to-deploy> -name <App-Installer-Name>

以上选项中可指定

  • -binarycreator /opt/Qt/Tools/QtInstallerFramework/4.8/bin/binarycreator
  • qifConfig <path-to-deploy>/config/config.xml
  • -qifLogo <path-to-logo>
  • -qifPackages <path-to-deploy>/packages
  • -qifResources <path-to-deploy>/resources/additional.qrc
  • -qifStyle <path-to-deploy/config/style.qss
    也可分开执行
/snap/bin/cqtdeployer -bin ~/YourApp/build/Desktop_Qt_6_8_0-Debug -qmlDir ~/YourApp/build/Desktop_Qt_6_8_0-Debug/qml -qmake /opt/Qt/6.8.0/gcc_64/bin/qmake
cp -r DistributionKit/* <path-to-deploy>/packages/com.vendor.product/data
/opt/Qt/Tools/QtInstallerFramework/4.8/bin/binarycreator -c config/config.xml -p packages <App-Installer-Name>

即可完成部署与制作安装包。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词