一般简单通过qt-creator创建新项目后的pro是这样:
#为项目添加模块
QT += core gui
# 如果QT的版本大于4 那么就添加widgets模块
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# 支持C++11标准
CONFIG += 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.0
#源文件
SOURCES += \
main.cpp \
mainwindow.cpp
#头文件
HEADERS += \
mainwindow.h
#界面文件
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
一.通过pro + pri方式有效管理工程,使其模块化
1.步骤:
1)到创建后的工程文件夹中,新建各个模块的文件夹,例如:SerialPort、Widget等文件夹
2)新建pri文件
3)在工程pro中导入pri文件
2.配置内容
1)(.pro)
#为项目添加模块 如果不需要界面可用QT -= gui
QT += core gui network serialport sql
# 如果QT的版本大于4 那么就添加widgets模块
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#app-建立一个应用程序的makefile(默认)
#lib(建立一个库的makefile)
TEMPLATE = app
#放置可执行程序目标的目录
DESTDIR = $$PWD/../Bin
#应用程序所需的额外的预处理程序定义的列表
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as 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 you use 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.0
#支持C++11标准
CONFIG += c++11
#版本号
VERSION_CUSTOM = 1.0.1
#生成目标程序名字
TARGET = ConfigTool-$$VERSION_CUSTOM
DEFINES += SOFTWARE_VERSION=$$TARGET
#源文件
SOURCES += \
main.cpp \
#导入pri
include($$PWD\Widget\Widget.pri)
include($$PWD\Business\Business.pri)
include($$PWD\IEC\IEC.pri)
include($$PWD\DataHandle\DataHandle.pri)
include($$PWD\Utility\Utility.pri)
include($$PWD\SerialPort\SerialPort.pri)
include($$PWD\MultiLanguage\MultiLanguage.pri)
#应用程序所需的额外的包含路径的列表
INCLUDEPATH += $$PWD/Business $$PWD/DataHandle $$PWD/IEC
INCLUDEPATH += $$PWD/MultiLanguage $$PWD/SerialPort
INCLUDEPATH += $$PWD/Utility $$PWD/Widget
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#应用图标
RC_ICONS += icon.ico
#中文
RC_LANG = 0x0004
# 公司名
QMAKE_TARGET_COMPANY = 科技股份有限责任公司
# 版权
QMAKE_TARGET_COPYRIGHT = Copyright(C) 2018-2019 the Qt company Ltd
2)(.pri)
#源文件
SOURCES += \
$$PWD\FFSerialPortCtl.cpp
#头文件
HEADERS += \
$$PWD\FFSerialPortCtl.h
二、通过 pro + pro + pri 工程集方式管理多个qt应用程序
1.工程集pro:
#可以创建一个能够进入特定目录并且为一个项目文件调用make的makefile
TEMPLATE = subdirs
#配置添加批处理、release方式
CONFIG += batch release
#添加各个工程的文件路径
SUBDIRS += \
libffcurl \
libsdk \
libmedia \
libwidgets \
libsearch \
IVSCMS \
libhttp \
IVSTools \
#添加翻译文件
## Must add language here, used for all project.
TRANSLATIONS += $$PWD/language/lang_en.ts
TRANSLATIONS += $$PWD/language/lang_cn.ts
TRANSLATIONS += $$PWD/language/lang_tw.ts
2.单个工程pro
QT += core gui network xml webenginewidgets multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = IPCTools
include($$PWD/../libcommon.pri)
contains(QT_ARCH, i386) {
DESTDIR = ivs-tools-x86
} else {
DESTDIR = ivs-tools-x64
}
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as 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
INCLUDEPATH += $$PWD/mainwin $$PWD/datalogic
INCLUDEPATH += $$PWD/mainwin/DevConfig
INCLUDEPATH += $$PWD/mainwin/DevSearch
INCLUDEPATH += $$PWD/mainwin/DevUpdate
INCLUDEPATH += $$PWD/mainwin/DevCalculate
# You can also make your code fail to compile if you use 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.
# disables all the APIs deprecated before Qt 6.0.0
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
#导入pri
include($$PWD\Widget\Widget.pri)
# Define resource files.
#.rc文件是管理程序icon、鼠标图片、等资源的脚本
RC_FILE += resource/image/Mainform/main.rc
#qrc文件路径
#qrc文件创建 右键创建资源文件
#添加前缀和添加文件后可以将图片资源添加到工程中,用于在代码中设置背景,图标
RESOURCES += resource/resource.qrc
3.单工程模块中的.pri文件
#指定文件各个模块包含的头文件、源文件和界面文件
SOURCES += \
bridge.cpp \
messagebox.cpp \
pushbutton.cpp \
qpasswordlineedit.cpp \
tipsslider.cpp \
webengineviewform.cpp \
tableheaderview.cpp \
clabel.cpp \
showcpumemory.cpp \
renamedialog.cpp \
jqcpumonitor.cpp \
networkconfigdialog.cpp
HEADERS += \
bridge.h \
dintvalidator.h \
messagebox.h \
nodashrectstyle.h \
pushbutton.h \
qpasswordlineedit.h \
singleton.h \
tipsslider.h \
webengineviewform.h \
tableheaderview.h \
clabel.h \
showcpumemory.h \
renamedialog.h \
jqcpumonitor.h \
networkconfigdialog.h
FORMS += \
messagebox.ui \
webengineviewform.ui \
renamedialog.ui \
networkconfigdialog.ui