How to add pre processing defs (macros) to qt creator?

From the QT Documentation:

The defines are specified in the .config file. The .config file is a regular C++ file, prepended to all your source files when they are parsed. Only use the .config file to add lines as in the example below:

#define NAME value

That is, if you import a project named MyProject, then the pre-processor definitions should be specified in MyProject.config

For my projects it causes the indexer to recognize this define project wide and changed the auto-complete to reflect this.


It depends:-)

The following is assuming you are using qmake based projects:

First you can add DEFINES += SOME_DEFINE=value into your .pro file. That is picked up inside creator and when building on the command line and should also show up when creating a MSVC or XCode project from the .pro file.

Then you can add DEFINES += SOME_DEFINE=value to the qmake call that Qt Creator will issue when configuring the project. That happens in the Project Mode, Build Settings, QMake Steps.

Finally, you can put #define SOME_DEFINE value liens into a header file and include that. That works for all kinds of projects:-)

Tags:

Qt

Qt Creator