一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

提要
当多人合作开发一个项目的时,若每人创建一个工程,就会出现同一个项目中多个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)。

posted on   一杯清酒邀明月  阅读(1070)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2021-04-20 Qt 日志功能(qDebug、qWarnng、qCritical、qFatal)
2021-04-20 Qt Excel进行新增、删除、修改读取从入门到精通
2020-04-20 相机系统综述(ISP)
2020-04-20 什么是ColorMatrix
2020-04-20 栈的C++实现(数组)—— 创建-push-pop-top-清空栈-处理栈
2020-04-20 C# PictureBox 的图像上使用鼠标画矩形框
2020-04-20 Halcon创建模板并进行模板匹配
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示