在 Qt 中包含 .pro 文件? [英] Include a .pro file in Qt?
问题描述
我有一个项目,它有很多包含路径、源文件和头文件.该项目作为一个独立的应用程序运行(它不是一个库).
I have a project which has lots of includepaths, source and header files. The project is run as a standalone application (it's not a library).
我想为该应用程序的新功能实施测试(Qt 单元测试框架),为此,我需要(应用程序)项目的包含、源代码和头文件在(测试)项目中可用.
I would like to implement tests (Qt unit test framework) for new features for that application and for that, I require the includes, sources and header files of the (application) project to be available in the (testing) project.
我尝试将以下内容放入测试项目 .pro 文件中:
I have tried putting the following in the testing project .pro file:
include(../application/app.pro) #app.pro is the application project
然而,首先它会抱怨 main.cpp
,如果我注释掉,就会出现解析错误.(评论 main.cpp 很糟糕,因为我正在更改主项目以便测试能够编译)
However first it complains about main.cpp
, and if I comment that out there is a parsing error. (commenting main.cpp is bad since I'm changing the main project just so that the testing will compile)
我可以通过手动复制(应用程序)项目中的所有包含路径、源和头字段来获得我想要的行为,但我正在寻找一种更简洁的方法.
I can get the behavior i want by manually copying all the includepath's, source and header fields from the (application) project but am looking for a cleaner way.
执行此操作的最佳方法是什么?是否可以轻松地将一个 .pro 包含到另一个中?
What would be the optimal way to do this? Is it possible to painlessly include one .pro into another?
推荐答案
您应该进行两个修改:
- 将所有头文件和特定于构建的设置分离到一个 *.pri 文件中.这是您需要的,而不是包含 *.pro.
- 将所有业务逻辑移到一个库中,以便能够在单独的项目中对其进行测试.
例如,您将拥有 build.pri:
E.g., you will have build.pri:
# build.pri
TOPDIR = $$PWD
INCLUDEPATH += . \
$$TOPDIR/include
DEPENDPATH += $$TOPDIR
INCLUDEPATH += $$TOPDIR/additional/libararies
HEADERS += all.h \
your.h \
headers.h \
of.h \
interest.h
QT += xml
# etc., etc.
和 core.pro
# core.pro
TEMPLATE = lib
CONFIG += dll thread create_prl
QT += network xml xmlpatterns sql
include(../build.pri)
HEADERS += \
headers.h
SOURCES += sources.cpp \
many_of_them.cpp
TARGET = core
# etc., etc.
(注意include(../build.pri)
),然后将你的主项目app.pro
作为subdirs
项目以 core
和 gui
作为应用程序的组件,test.pro
具有强制性的 core
和尽可能多的测试你想要.
(note the include(../build.pri)
), and then make your main project app.pro
as a subdirs
project with core
and gui
as components of application, and test.pro
with obligative core
and as many tests as you want.
这篇关于在 Qt 中包含 .pro 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!