【发布时间】:2014-01-03 21:02:41
【问题描述】:
这是Qt documentation的引用:
有些资源需要根据用户的语言环境而改变,例如 翻译文件或图标。这是通过将 lang 属性添加到 qresource 标记,指定合适的语言环境字符串。例如:
<qresource> <file>cut.jpg</file> </qresource> <qresource lang="fr"> <file alias="cut.jpg">cut_fr.jpg</file> </qresource>如果用户的语言环境是法语(即 QLocale::system().name() 返回 "fr_FR"), :/cut.jpg 成为对 cut_fr.jpg 图像的引用。为了 其他语言环境,使用 cut.jpg。
我尝试这样做,但我失败了。这是我的 *.qrc 文件的一部分:
<qresource>
<file>HtmlTemplates/angle.html</file>
<file>HtmlTemplates/bottom.html</file>
<file>HtmlTemplates/top.html</file>
</qresource>
<qresource lang="en">
<file alias="HtmlTemplates/angle.html">HtmlTemplates/en/angle.html</file>
<file alias="HtmlTemplates/bottom.html">HtmlTemplates/en/bottom.html</file>
<file alias="HtmlTemplates/top.html">HtmlTemplates/en/top.html</file>
</qresource>
如您所见,它遵循与手册中的示例完全相同的模式。 但是,尝试编译此文件会产生以下结果:
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'angle.html'
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'bottom.html'
..\Blinky_2.0\resources.qrc: Warning: potential duplicate alias detected: 'top.html'
如果我尝试在 QtCreator 中修改 *.qrc 文件,它会将其重置为错误状态,删除 lang 属性:
<qresource prefix="/">
<file>HtmlTemplates/angle.html</file>
<file>HtmlTemplates/bottom.html</file>
<file>HtmlTemplates/top.html</file>
<file alias="HtmlTemplates/angle.html">HtmlTemplates/en/angle.html</file>
<file alias="HtmlTemplates/bottom.html">HtmlTemplates/en/bottom.html</file>
<file alias="HtmlTemplates/top.html">HtmlTemplates/en/top.html</file>
</qresource>
所以我不得不在我的代码中迭代不同语言环境的资源。我错过了什么还是这是一个 Qt 错误? Qt版本是4.8.4,QtCreator版本是2.8.1。
【问题讨论】:
标签: c++ qt qt4 embedded-resource rcc