QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
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 \
timerdialog.cpp
HEADERS += \
timerdialog.h
FORMS += \
timerdialog.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Qt 项目的 .pro
文件,也称为项目文件。它定义了构建项目时 qmake 工具所需的各种参数和源文件。以下是这段 .pro
文件内容的详细解释:
-
QT += core gui
- 这表示项目需要 Qt 的核心模块(
core
)和图形用户界面模块(gui
)。
- 这表示项目需要 Qt 的核心模块(
-
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
- 这是一个条件判断。如果 Qt 的主版本号大于 4(即 Qt 5 或更高版本),则还需要
widgets
模块。在 Qt 5 中,widgets
模块被分离出来,而在 Qt 4 中,它是gui
模块的一部分。
- 这是一个条件判断。如果 Qt 的主版本号大于 4(即 Qt 5 或更高版本),则还需要
-
CONFIG += c++11
- 这表示项目将使用 C++11 标准来编译。
-
DEFINES += QT_DEPRECATED_WARNINGS
- 这将定义
QT_DEPRECATED_WARNINGS
宏,使得编译器在使用已弃用的 Qt 功能时发出警告。
- 这将定义
-
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
- 这行被注释掉了,但如果取消注释,它会定义一个宏,使编译器在遇到 Qt 6.0.0 之前弃用的 API 时发出错误(而不是警告)。这样,你的代码将不能编译,直到你移除了所有这些弃用的 API。
-
SOURCES, HEADERS, FORMS
SOURCES
列出了所有源文件(.cpp
文件)。HEADERS
列出了所有头文件(.h
文件)。FORMS
列出了所有 Qt 设计师界面文件(.ui
文件)。
-
qnx: target.path = ...
- 这是特定于 QNX(一种实时操作系统)的部署规则。它定义了目标应用程序的安装路径。
-
else: unix:!android: target.path = ...
- 这是一个条件规则,用于除 QNX 和 Android 之外的 Unix 系统。它同样定义了目标应用程序的安装路径。
-
!isEmpty(target.path): INSTALLS += target
- 这是一个条件语句,如果
target.path
不为空(即定义了安装路径),则将目标(即构建的应用程序)添加到安装列表中。
- 这是一个条件语句,如果