Goal: Generate/update the *.ts files of a Qt widgets app using lupdate.
Setup:
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
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:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With