Setting environment variables for build in Visual Studio (2008)

11.8k views Asked by At

I looked at some projects generated by the Qt plugin for VS and noticed that they use the environment variable QTDIR to refer for example to the Qt header files. However I failed to figure out where this variable is set. I guess it must be somewhere in the project settings, however I could not find it. Also please note that I am referring to the environment variables required during the build, not the ones for debugging.

2

There are 2 answers

0
stijn On

On Windows there are two ways to set an environment variable like QTDIR: either permanently in System Properties->Advanced->Environment Variables or temporarily for a single cmd session by opening cmd.exe and executing set QTDIR=/path/to/qt; now when starting VS from that commandline (execute devenv.exe) it will use the QTDIR value just set. The second case you use mainly when you have multiple QT installations.

Apart from that, you can also use User Macros in VS Property sheets. From the build tools' point of view they are sort of equivalent to environment variables. Add a new property sheet to your project, double click on the new sheet, go to the User Macros page and click on Add Macro. Nice thing is you can share this property sheet amongst all your Qt projects.

4
Tim Meyer On

When you install Qt through the setup wizard (i.e. not manually), the installation process sets the system environment variable QTDIR. This is not a project-specific thing, it is set for your whole system. You can check that at the location stijn described.

Hint: You can press Win+Pause to open the system properties dialog (where Win is the key between Ctrl and Alt)