创建 Qt 资源集合文件
Qt 资源系统是一种将文件存储在应用程序可执行文件中的平台独立机制。如果您的应用程序始终需要一组特定的文件(如图标、翻译文件、图像),且您不想使用特定于系统的手段来打包和定位这些资源,请使用该机制。
您可以创建和编辑 Qt 资源集合(.qrc )文件。
创建 QRC 文件
要创建新的 QRC 文件:
- 转到“Welcome ”,然后选择“New project ”。
- 在File 中,选择Qt resource file 。

- 在Name 中,为文件输入名称。
- 在“Create in ”中,输入文件的路径。
- 选择“Create ”以创建该文件。
编辑 QRC 文件
添加具有不同前缀的组,以对资源进行结构化组织,并避免在不同的库或插件中通过不同的.qrc 文件添加的资源文件之间发生冲突。
有时,在运行时将资源文件放在不同的路径下会比较方便。.qrc 文件可以通过设置“alias ”属性来实现这一点。
要编辑 QRC 文件:
- 打开一个
.qrc文件。
- 选择“Files ”以将文件添加到该组。
- 在“Alias ”中,设置运行时资源文件所在的路径。
- 在“Prefix ”中,设置一个前缀,该前缀将添加到每个本地文件名中,从而确定该文件在资源系统中的名称。
- 在“Language ”中,设置一个合适的区域设置字符串,以便根据用户的区域设置选择资源,例如翻译文件或图标。
另请参阅 《教程:Qt Widgets 应用程序》和《创建Qt项目》。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.