0
votes

Some QMake projects use system() commands which are only meant to be executed during the build, and usually only for a specific OS, for example:

win32:system(cmd.exe /E myscript.bat)

Historically, Qt Creator has ignored such commands when parsing .pro/.pri files. But starting with Qt Creator 4.13.0, it now runs them during project loading, which can result in unexpected actions or failures.

How can we tell Qt Creator not to parse specific statements or blocks from a .pro/.pri file, so that they only get executed by QMake itself?

1
@eyllanesc thanks for the edit, but it really is Qt Creator in the title, not Qt. The trick is about Qt Creator itself parsing QMake project files. I don't think "How can I make Qt ignore some QMake commands in my .pro file" is accurate.Romain Pokrzywka
If you analyze your question better you will see that it is independent of QtCreator, you will see that the command works if you open a terminal and compile the project without QtCreator.eyllanesc

1 Answers

0
votes

You can disable such commands, or any other QMake statement that you don't want parsed by Qt Creator, by enclosing the command in a !qtc_run {} block or inline condition:

!qtc_run {
    win32:system(copy myfile.txt dest\\folder)
    else:system(cp myfile.txt dest/folder)
}

!qtc_run:win32:system(cmd.exe /E myscript.bat)

The qtc_run token is added to the CONFIG variable by Qt Creator when it parses the QMake project, so it's not set when running qmake directly, and since CONFIG variables can be used for conditional blocks you can then test for the Qt Creator environment as done above.

You can also use this technique to only run some QMake commands when inside Qt Creator, simply by using qtc_run {} without the negation operator.