提要
當多人合作開發一個項目的時,若每人創建一個工程,就會出現同一個項目中多個pro文件。pri文件就是解決多個pro文件的一種方式,方便了最后代碼的合並。
示例
1.如何建立pri文件
2.pri文件與pro文件之間的聯系怎樣建立
如何建立pri文件
創建一個項目,在項目文件夾下創建一個文本文件,即txt文件,創建后修改其名稱為xxx.pri;
.pri文件與pro文件之間的聯系怎樣建立
繼上面創建好項目和pri文件后,用QtCreate打開項目,進入.pro文件,假如你的pro文件是這樣的;
1 QT += core gui 2
3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4
5 CONFIG += c++11
6
7 # The following define makes your compiler emit warnings if you use 8 # any Qt feature that has been marked deprecated (the exact warnings 9 # depend on your compiler). Please consult the documentation of the 10 # deprecated API in order to know how to port your code away from it. 11 DEFINES += QT_DEPRECATED_WARNINGS 12
13 # You can also make your code fail to compile if it uses deprecated APIs. 14 # In order to do so, uncomment the following line. 15 # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17
18 SOURCES += \ 19 main.cpp \ 20 largescreenlistwidget.cpp 21
22 HEADERS += \ 23 dataStruct.h \ 24 largescreenlistwidget.h 25
26 FORMS += \ 27 largescreenlistwidget.ui 28
29 # Default rules for deployment. 30 qnx: target.path = /tmp/$${TARGET}/bin 31 else: unix:!android: target.path = /opt/$${TARGET}/bin 32 !isEmpty(target.path): INSTALLS += target 33
34 DISTFILES +=
可以看到pro文件包含了源文件,頭文件,ui文件,此時將源文件,頭文件,ui文件部分,剪切下來粘貼到pri文件中。
下面是pri文件的內容:
1 SOURCES += \ 2 main.cpp \ 3 largescreenlistwidget.cpp 4
5 HEADERS += \ 6 dataStruct.h \ 7 largescreenlistwidget.h 8
9 FORMS += \ 10 largescreenlistwidget.ui
pri文件保存之后,進入到pro文件,將其內容改為以下:
1 QT += core gui 2
3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4
5 CONFIG += c++11
6
7 # The following define makes your compiler emit warnings if you use 8 # any Qt feature that has been marked deprecated (the exact warnings 9 # depend on your compiler). Please consult the documentation of the 10 # deprecated API in order to know how to port your code away from it. 11 DEFINES += QT_DEPRECATED_WARNINGS 12
13 # You can also make your code fail to compile if it uses deprecated APIs. 14 # In order to do so, uncomment the following line. 15 # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17
18 include(largescreenlistwidget.pri) 19
20 # Default rules for deployment. 21 qnx: target.path = /tmp/$${TARGET}/bin 22 else: unix:!android: target.path = /opt/$${TARGET}/bin 23 !isEmpty(target.path): INSTALLS += target 24
25 DISTFILES +=
相比於之前的pro文件,此時的pro文件將pri文件的 內容包含了進來,實際上相當於將之前的源文件,頭文件,ui文件放在了pri文件,將pri文件當作了頭文件一樣被包含進來。即之前包含的源文件,頭文件,ui文件部分,變為了include(largescreenlistwidget.pri)。