Skip to content

Instantly share code, notes, and snippets.

@codeyash
Created April 2, 2015 18:09
Show Gist options
  • Save codeyash/90e15d9a78e2c9c45cd0 to your computer and use it in GitHub Desktop.
Save codeyash/90e15d9a78e2c9c45cd0 to your computer and use it in GitHub Desktop.
Using variables from project file (.pro) into C++ code
http://qtway.blogspot.in/2013/04/using-variables-from-project-file-pro.html
Have you ever wonder if any of the variables you have defined in your project file (.pro) can be used in your C++ source code? The answer is yes, and the process is straightforward.
Let's say you export the variables in the project file as macros (in this case you set the target name for the application), then using it from C++ is just simple.
In the project file (.pro)
TARGET = YourApp
TEMPLATE = app
DEFINES += TARGET=\\\"$TARGET\\\"
then you can use it in your C++ code like this:
// translation files are stored in resource file as YourApp_locale.qm
if translator.load(QString(TARGET) + "_" + locale, ":/languages") {
...
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment