在* .pro文件之间传递变量

时间:2012-07-07 14:39:31

标签: qt global-variables qmake

我有以下* .pro文件:

领导解决方案的人

# head - pro file :
TEMPLATE = subdirs
CONFIG = qt thread ordered

# save root directory
PROJECT_ROOT_DIRECTORY = $$_PRO_FILE_PWD_
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") // output : "Master pro file path : [/Path/To/Directory]"

# project subdirs
SUBDIRS += PROJECT1

# PROJECT1 - pro file :
TEMPLATE = app

# etc.

# output 'PROJECT_ROOT_DIRECTORY ' contents
message("Master pro file path : "$${PROJECT_ROOT_DIRECTORY}) // output :  "Master pro file path : []"

如何在2个pro文件之间传递变量(此处变量为PROJECT_ROOT_DIRECTORY)?

修改:

这是与此this one相同的问题,但我不知道“另一个选项”的答案如何帮助我。

1 个答案:

答案 0 :(得分:8)

您可以将变量定义放在.pri文件中,然后将其包含在所需的所有.pro文件中。请注意,您需要告诉子目录中的.pro个文件找到.pri文件的路径。

<强> head.pro:

# head - pro file :
TEMPLATE = subdirs
CONFIG = qt thread ordered

# configuration
include(config.pri)
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") # output : "Master pro file path : [/Path/To/Directory]"

# project subdirs
SUBDIRS += PROJECT1

<强> config.pri:

# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!

<强> PROJECT1 / project1.pro:

# PROJECT1 - pro file :
TEMPLATE = app

# configuration
include(../config.pri)  # note that you need to put "../" before the .pri path
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") # should now output :  "Master pro file path : [/Path/To/Directory]"