2024.9.5 作业

注释QT基础代码

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.
#定义宏,使编译器在遇到已弃用的Qt特性时发出警告
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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow> //包含Qt的QMainWindow类,这是所有主窗口类的基类

//QT_BEGIN_NAMESPACE和QT_END_NAMESPACE用于定义命名空间的开始和结束
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } //声明一个名为Ui的命名空间,并在其中声明一个名为MainWindow的类
QT_END_NAMESPACE

class MainWindow : public QMainWindow //声明MainWindow类,它继承自QMainWindow
{
    Q_OBJECT //这是一个宏,用于启用Qt的元对象系统,包括信号和槽机制

public:
    MainWindow(QWidget *parent = nullptr); //构造函数,可以指定一个父窗口
    ~MainWindow(); //析构函数

private:
    Ui::MainWindow *ui; //私有成员变量,用于存储用户界面对象的指针
};

#endif
#include "mainwindow.h" //包含主窗口类的头文件

#include <QApplication> //包含QApplication类的头文件,这是所有Qt应用程序必须的

int main(int argc, char *argv[]) //main函数,程序的入口点
{
    QApplication a(argc, argv); //创建一个QApplication对象,传递命令行参数
    MainWindow w; //创建MainWindow类的实例
    w.show(); //显示主窗口
    return a.exec(); //进入Qt的事件循环,等待用户操作
}
#include "mainwindow.h" //包含主窗口类的头文件
#include "ui_mainwindow.h" //包含由Qt Designer生成的用户界面类的头文件

//MainWindow类的构造函数
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent) //调用QMainWindow的构造函数,传递父窗口指针
    , ui(new Ui::MainWindow) //创建Ui::MainWindow类的实例,并初始化ui成员变量
{
    ui->setupUi(this); //调用setupUi函数,设置用户界面
}

//MainWindow类的析构函数
MainWindow::~MainWindow()
{
    delete ui; //删除Ui::MainWindow类的实例,释放内存
}

思维导图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值