总体文件
my_app.pro
QT += core gui //用来增加模块,想要加模块直接空格加模块名
//重点:假设想用网络模块,要在这边添加network模块
//还需要在mainwindow.h文件里面#include 对应库
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 //c++11是一种编译标准
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
翻译:
# 如果代码使用已弃用的 API,则可能会使代码无法编译。
# 为此,请取消注释以下行。
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # 禁用在 Qt 6.0.0 之前弃用的所有 API
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
编译运行之后,与你项目相同目录下会产生一个debug文件夹
会产生一个可执行文件(运行这个可执行文件,就相当于你运行项目)
在.pro文件中加入一个属性 TARGET
TARGET = hello
debug文件夹下就会产生相对应名字的可执行文件
main.c文件介绍
#include "mainwindow.h"
#include <QApplication>
//程序入口
int main(int argc, char *argv[])
{
//argc是命令行参数数量,argv是命令行参数的内容
//QApplication a(argc, argv),管理QT程序的运行,设置QT应用程序,针对QWidget
//QGuilication a(argc, argv),管理QT程序的运行,设置QT应用程序,针对QQuick
//QCorelication a(argc, argv),管理QT程序的运行,设置QT应用程序,针对无界面
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec(); //事件循环,卡在这等待鼠标键盘等其他的输入
}