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

Viewed 49815

In Eclipse there is an option to specify pre processing defines (#ifdef macros) to a project by using the Symbols option in Paths and Symbols. This helps in effective indexing of code which is cross platform. Is there any option to provide these in Qt creator?

6 Answers

First suggestion from @Tobias Hunger's answer worked for me. I was doing this in my .pro file:

DEFINE += KEY=value

which did not work until I changed it to:

DEFINES += KEY=value

That said, if you want to do everything from the command line, an almost hybrid solution that does not use Qt Creator GUI, but does use .pro files, is described here:

https://www.linux.org/threads/c-tutorial-create-qt-applications-without-qtcreator.18409/

Using the method described in the above link, you can use qtcreator -project to produce a .pro file, then use notepad or vim or some other text editor to add the DEFINES += KEY=value line to the .pro file you just created. Then use qmake thusly: qmake <your_project>.pro, to do the Qt pre-processing, and finally just make to build an executable.

I've also heard lore of a qtcreator -D option to add preprocessor defines from the command line as described here: https://doc.qt.io/archives/qt-4.8/qmake-variable-reference.html#defines but I've never tried it.

Hope something works for you! Your dedication to the CLI is admirable.

Related