提要
当多人合作开发一个项目的时,若每人创建一个工程,就会出现同一个项目中多个pro文件。pri文件就是解决多个pro文件的一种方式,方便了最后代码的合并。
示例
1.如何建立pri文件
2.pri文件与pro文件之间的联系怎样建立
如何建立pri文件
创建一个项目,在项目文件夹下创建一个文本文件,即txt文件,创建后修改其名称为xxx.pri;
.pri文件与pro文件之间的联系怎样建立
继上面创建好项目和pri文件后,用QtCreate打开项目,进入.pro文件,假如你的pro文件是这样的;
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \largescreenlistwidget.cppHEADERS += \dataStruct.h \largescreenlistwidget.hFORMS += \largescreenlistwidget.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetDISTFILES +=
可以看到pro文件包含了源文件,头文件,ui文件,此时将源文件,头文件,ui文件部分,剪切下来粘贴到pri文件中。
下面是pri文件的内容:
SOURCES += \main.cpp \largescreenlistwidget.cppHEADERS += \dataStruct.h \largescreenlistwidget.hFORMS += \largescreenlistwidget.ui
pri文件保存之后,进入到pro文件,将其内容改为以下:
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0include(largescreenlistwidget.pri)# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetDISTFILES +=
相比于之前的pro文件,此时的pro文件将pri文件的 内容包含了进来,实际上相当于将之前的源文件,头文件,ui文件放在了pri文件,将pri文件当作了头文件一样被包含进来。即之前包含的源文件,头文件,ui文件部分,变为了include(largescreenlistwidget.pri)。
参考
https://blog.csdn.net/qq_41673920/article/details/96153657