本文介绍了如何指定自动生成的资源文件给 Qmake?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有德语翻译的Qt项目,Translation_de.ts,它通过Qmake自动编译成Translation_de.qm:

I have a Qt project with a german translation, Translation_de.ts, which is automatically compiled into Translation_de.qm via Qmake:

TRANSLATIONS += Translation_de.ts
...
QMAKE_EXTRA_COMPILERS += lrelease
lrelease.input         = TRANSLATIONS
lrelease.output        = ${QMAKE_FILE_BASE}.qm
lrelease.commands      = $$[QT_INSTALL_BINS]/lrelease ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_BASE}.qm
lrelease.CONFIG       += no_link target_predeps

然后将生成的 Translation_de.qm 作为资源编译到最终应用程序中:

The generated Translation_de.qm is then compiled into the final application as a resource:

RESOURCES += Resources.qrc

其中 Resources.qrc 看起来像这样:

where Resources.qrc looks like this:

<RCC>
  <qresource>
    ...
    <file>Translation_de.qm</file>
  </qresource>
</RCC>

所有这些工作正常,除了在新结账时第一次调用 Qmake 会抛出以下烦人的警告:

All of this works fine, except that the very first call to Qmake on a fresh checkout throws the following annoying warning:

RCC: Error in 'Resources.qrc': Cannot find file 'Translation_de.qm'

我在这里做错了什么?如何正确指定自动生成的资源文件,例如 Translation_de.qm?

What am I doing wrong here? How do I correctly specify an auto-generated resource file like Translation_de.qm?

推荐答案

在 qmake 阶段创建生成的文件,例如system(lrelease...).保留其他规则,以便在更改输入文件时不必重新运行 qmake.

Create the generated files in qmake phase with e.g. system(lrelease...). Leave the other rules in place too so you don't have to rerun qmake when the input files are changed.

这篇关于如何指定自动生成的资源文件给 Qmake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-25 17:22