0

With the following dummy qmake syntax I am trying to set an environment variable and then check it later:

MY_VAR = true
message("A")
defined(MY_VAR){
    message("B")
}

The unintuitive part for me is that upon running this qmake script, only "A" is outputted to the console and not "B";

So what is the correct way of setting an environment variable in qmake?

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • Note: the .pro is only used when the program is compiled, not when it is executed, so I don't see the point of environment variables. If you want to configure something in the build then use DEFINE. – eyllanesc May 08 '22 at 17:36
  • Does this answer your question? [QMake - How to add and use a variable into the .pro file](https://stackoverflow.com/questions/7754218/qmake-how-to-add-and-use-a-variable-into-the-pro-file) – talamaki May 09 '22 at 18:21
  • Nope. It does not say how to test a variable in .pro file or in code. – Mr. Developerdude May 09 '22 at 22:04

1 Answers1

0

To check for variable existence you must invoke

defined(MY_VAR, var): message(...)

BTW. this is a regular qmake variable, not environment variable.

Matt
  • 13,674
  • 1
  • 18
  • 27