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

Qt 在*.pro文件之间传递变量,qt,global-variables,qmake,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 pat

我有以下*.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

如何在两个pro文件之间传递变量(此处变量为
PROJECT\u ROOT\u目录

编辑:

# 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
# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!
# 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]"

这是与此相同的问题,但我看不出“另一个选项是”答案对我有什么帮助。

您可以将变量定义放在
.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
# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!
# 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]"
config.pri:

# 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
# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!
# 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]"
project1/project1.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
# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!
# 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]"

好的,听起来不错。因此,这始终是一个解决问题,您不能在
*.pro
文件之间按值传递变量?至少我不知道这样做的方法。也许有更好的解决办法。如果其他人发布了更好的解决方案,请毫不犹豫地移动接受。。。这可能是一个在qt-5之后在.qmake.conf中定义变量的解决方案。您重新发布了吗?如果你没有得到正确的答案,你为什么要把它设为被接受呢?@patrickbass是的,你是对的,它不是很一致。但是,如果有更好的答案出现,我会提出接受