Qt之路(1)---.pro文件介绍

使用Qt向导生成的应用程序.pro文件格式如下:

#-------------------------------------------------
#
# Project created by QtCreator 2022-02-16T13:07:45
#
#-------------------------------------------------

//模块的名字
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = QtTest         //应用程序名
TEMPLATE = app          //生成的makefile的模板类型

# 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

CONFIG += c++11

//源文件
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

RESOURCES += \
    painer.qrc

.pro就是工程文件(project),它是qmake自动生成的用于生产makefile的配置文件
.pro文件的写法如下:

注释:从“#”开始,到这一行结束。

模板变量告诉qmake为这个应用程序生成哪种makefile。下面是可供使用的选择:TEMPLATE=app

  • app–建立一个应用程序的makefile。这是默认值,所以如果模块没有被制定,这个将被使用。
  • lib–建立一个库的makefile。
  • vcapp–建立一个应用程序的VisualStudio项目文件。
  • vclib–建立一个库的VisualStudio项目文件。
  • subdirs–这是一个页数的模板,它可以创建一个能够进入特定目录并且为一个项目文件生成makefile并且为它调用make的makefile。

指定生成的应用程序名:

TARGET = QtDemo

#工程中包含的头文件:
HEADERS += mainwindow.h

#工程中包含的.UI设计文件:
FORMS += mainwindow.ui

#工程中包含的源文件:
SOURCES += main.cpp mainwindow.cpp

#工程中包含的资源文件:
RESOURCES += painer.qrc

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

这条 语句的含义是,如果 N QT_MAJOR_VERSION 大于 4 4 (也就是 当前使用的 的 Qt5及 更高版本) 需要 增加 s widgets 模块。如果 项目 仅需 支持 Qt5 , 也可以直接添加 “QT += widgets” 一句。不过为了保持代码 兼容 ,最好还是按照QtCreator 生成的语句编写。

CONFIG 用来告诉 qmake 关于应用程序的配置信息。

CONFIG += c++11 //使用 c++11 的特性

在这里使用“+=”,是因为我们添加我们的配置选项到任何一个已经存在中。这样做比使用“=”那样替换已经指定的所有选项更安全。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

工地码哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值