How to specify auto-generated resource files to Qmake?

本秂侑毒 提交于 2019-12-10 12:52:12

问题


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

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

RESOURCES += Resources.qrc

where Resources.qrc looks like this:

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

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'

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


回答1:


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.




回答2:


http://doc.qt.io/qt-5/qmake-variable-reference.html

CONFIG+=lrelease #generates *.qm files from TRANSLATIONS= to the directory builddir/.qm/ CONFIG+=embed_translations #adds them as qrc resources

so (other than)

CONFIG+=lrelease embed_translations

no qmake magic is required. Your qm files will be under :/i18n/ unless you specify otherwise with

QM_FILES_RESOURCE_PREFIX=/my/customtranslationdirectory



回答3:


I think that what you want is just "ignore_no_exist" for lrelease.CONFIG

As far as I know the target_predeps ensures that it is executed before the 'normal' compilation steps are issued. So if it's really only about getting rid of the warning, just add the above given flag. Your qm creation should work once you execute the makefile that was created by the qmake call.

If your qm files are not created try to add:

    PRE_TARGETDEPS += compiler_lrelease_make_all

Check out this link for more options that might help you.



来源:https://stackoverflow.com/questions/4366898/how-to-specify-auto-generated-resource-files-to-qmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!