-->

How to make QtLinguist shipped with Qt 5.9.1 work?

2020-08-13 02:45发布

问题:

Goal: Generate/update the *.ts files of a Qt widgets app using lupdate.

Setup:

  • Windows 7 Pro 64 (tried on Windows 10 Home as well)
  • Qt 5.9.1 Prebult Components for msvc2017 64-bit,
  • Visual Studio Community 2017.

The problem: I have run lupdate from the QtCreator, as well as manually from the console, but in neither case it is working. The message is:

Starting external tool "C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin\lupdate.exe" C:/Documents/Projects/untitled1/untitled1.pro WARNING: Project ERROR: Cannot run compiler 'cl'. Maybe you forgot to setup the environment?

"C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin\lupdate.exe" finished

Otherwise the project is compiled, run and debugged without problems with the kit: Desktop Qt 5.9.1 MSVC2017 64bit (default), which is the reason I think the environment is properly set up.

I can't find any information regarding this issue. Any ideas how to make lupdate work?

EDIT: I am adding screenshots of the current setup (which is made by the Qt installer) in attempt to clarify why I believe the environment is properly set up:

kits

cmake configuration

回答1:

The solution

Here is the solution I've found (rather hack-ish, but not too much), based on the info and advices kindly provided by n.m. in the comments under the question:

  1. Create a translate.bat with the following single-line content:

    "%programfiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" & lupdate.exe %1

and put it under %{CurrentProject:QT_INSTALL_BINS} (in my case C:\Qt\Qt5.9.1\5.9.1\msvc2017_64\bin). Make sure that the translate.bat contains the correct path to vcvars64.bat on your machine. You may as well put another version of vcvars if you need.

  1. In Qt Creator select Tools/Options/Environment/External Tools and then Add Tool under Linguist category. Name it something like Create/Update TS files. Setup the fields for this entry as follows:

    • Executable: %{CurrentProject:QT_INSTALL_BINS}\translate.bat,

    • Arguments: %{CurrentProject:FilePath},

    • Working directory: %{CurrentProject:QT_INSTALL_BINS},

as shown here: External Tools, then apply the changes and close the Options window.

  1. Go to Tools/External/Linguist, select Create/Update TS files and now it should do the job as usual.

The background

Here is once again the link, provided by n.m. in the comments, which served as a base for this solution. Here is also n.m.'s explaination:

Running lupdate from the console most definitely requires that you run vcbars*.bat as described in the link I gave you. That's because lupdate wants to run the compiler and it has no idea where to find it. vcbars*.bat tweaks your PATH and other environment variables. In theory the GUI should set up the environment for you, but in practice it probably doesn't.



回答2:

If you are using Qt5.9.1 of mingw version, you may need to config the system path for mingw compiling tools.



回答3:

In my case the culprit was the fact that Qt Creator had somehow picked different target ABIs for C and C++:

After fixing this, I managed to get lupdate running with no issues.



回答4:

You have to run lupdate.exe from VS2015 x86 Native Tools Command Prompt console.