Qt Visual Studio Add-in 导出的 .pri 怎么用?

今天咱们介绍一下 Qt Add-in 导出的 pri 文件怎么用.
 
一般需要导出这个文件, 主要应该是跨平台编译的需求, 所以这个文件里包含的东西会比较少, 咱们看下导出的文件是什么样子的:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------
 
# This is a reminder that you are using a generated .pro file.
# Remove it when you are finished editing this file.
message("You are running qmake on a generated .pro file. This may not work!")
 
SOURCES += ./main.cpp
这是我建的一个最简单的qt项目, 里面只包含一个 main.cpp 文件.
可以看到, 导出的 pri 里也只包含这些内容, 其他的什么 template, config 什么的一概没有, 可以看到注释也说直接用是不行滴!
那该咋用这个文件呢!
 
其实说起来就比较简单了, 就几步:
1. 修改 pri 文件, 添加 template, config等项, 比如我这个是exe的程序, 修改完后是这样的:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------
 
# This is a reminder that you are using a generated .pro file.
# Remove it when you are finished editing this file.
#message("You are running qmake on a generated .pro file. This may not work!")
 
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
 
SOURCES += ./main.cpp
    这里的东西其实用QtCreator随便建个项目, 就知道怎么写了.
2. 用 QtCreator 建一个空的Qt项目
3. 在项目目录下建个子文件夹(不是必须, 主要是看着舒服), 把 pri 文件和所有的 .h 和 .cpp 文件都拷到这个目录下
4. 修改 pro 文件, 添加一句
include(xxx/myapp.pri)
 
这就完事了.
 
然后构建整个项目, 你就会发现程序可以正确的编译了!
 
ps:
因为pri文件是include进来的, 所以在include之前写的所有设置 pri文件 都是可以继承!
这个特性是很用的, 比如我的好几个项目都需要依赖osg的库, 去改每个 pri 文件太累了, 这个时候就可以把这些配置都写在 pro 文件里.
比如, 我的 pro 文件最后就是这样滴:
INCLUDEPATH += $$(OSG_DIR)/include
LIBS += -L$$(OSG_DIR)/lib
LIBS += -losg -losgViewer -losgGA -lOpenThreads -losgDB
 
include(xxx/myapp.pri)
 
这里的 $$ 是用来访问环境变量的, 你也可以直接写绝对路径哦.



原文地址:https://www.cnblogs.com/chaoswong/p/3569644.html