参考:
QT中PRO文件写法的详细介绍,很有用,很重要!_adriano119的博客-CSDN博客
我的实例:
#-------------------------------------------------
#
# Project created by QtCreator 2019-02-27T19:20:15
#
#-------------------------------------------------
QT += core gui network serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#指定生成的应用程序名
TARGET = FDCollector_xxxx
#TEMPLATE
#模板变量告诉qmake为这个应用程序生成哪种makefile。下面是可供使用的选择:TEMPLATE = app
#app:建立一个应用程序的makefile。这是默认值,所以如果模板没有被指定,这个将被使用。
#lib :建立一个库的makefile。
#vcapp:建立一个应用程序的VisualStudio项目文件。
#vclib: 建立一个库的VisualStudio项目文件。
#subdirs :这是一个特殊的模板,它可以创建一个能够进入特定目录并且为一个项目文件生成makefile并且为它调用make的makefile。
TEMPLATE = app
#指定目标文件(obj)的存放目录
OBJECTS_DIR += $$PWD/bin/build/objects
#源文件编码方式
CODECFORSRC = UTF-8
#使用 Log4Qt
include(log4qt/log4qt.pri)
INCLUDEPATH += log4qt
# 条件编译设置
# 使用方法:
# #ifdef Debug
# //Debug环境代码
# #else
# //Realse环境代码
# #endif
DEFINES += Debug
#DEFINES += Release
# 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
# 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
SOURCES += main.cpp\
comchange.cpp \
mainwindow.cpp \
login.cpp \
webrequest.cpp
HEADERS += mainwindow.h \
comchange.h \
login.h \
sample.h \
webrequest.h
FORMS += mainwindow.ui \
login.ui \
url.ui \
test.ui \
serial.ui
#设置配置文件,并windows路径格式化
ConfFile = $$PWD/conf.ini
ConfFile = $$replace(ConfFile, /, \\)
CONFIG +=debug_and_release
debug
{
#debug的结果运行程序放这里
DESTDIR= $$PWD/bin/debug
MOC_DIR = $$PWD/bin/build/debug
#复制conf.ini到debug文件夹里
# OutputDir = $$replace(DESTDIR, /, \\)
# QMAKE_POST_LINK += copy /Y $$ConfFile $$OutputDir
}
release
{
#release的结果运行程序放这里
DESTDIR = $$PWD/bin/release
MOC_DIR = $$PWD/bin/build/release
#复制conf.ini到release文件夹里
# OutputDir = $$replace(DESTDIR, /, \\)
# QMAKE_POST_LINK += copy /Y $$ConfFile $$OutputDir
}
#复制conf.ini到运行文件夹里
OutputDir = $$replace(DESTDIR, /, \\)
QMAKE_POST_LINK += copy /Y $$ConfFile $$OutputDir
RESOURCES += \
res.qrc
RC_ICONS = res\fd16.ico
#将配置文件加入项目中
DISTFILES += \
conf.ini \
readme.md
另外,需要让build的过程数据,统一输出到一个位置,需要作如下设置:
参考:https://jingyan.baidu.com/article/6181c3e0b9d170152ef153af.html
完成后,退出QT Creator,然后在项目文件夹中删除“*.pro.user”配置文件,然后重新启动QT Creator。
再次编连项目的时候,就全部都在app/bin下面了。