Qt第一天

Qt基础结构

在创建项目的时候,在Details子目录下,需要选择Base class类,其中具有以下三种,

  • QWidget ->最基础的窗口类,Qt里面能看到的东西的基类
    • QMainWindow -> 具有菜单栏,工具栏,状态栏
    • QDialong -> 对话框,没有最大化的窗口

创建后见面如下:

qt1.png

我们对每一个文件夹进行访问解释:

.pro可以看成vs的解决方案->project

main.cpp

#include "learnqt.h"//自己建造的头文件
#include <QApplication>//包含一个应用程序的类的头文件

//argc 命令行变量的数量
//argv 命令行的变量的数组

int main(int argc, char *argv[])
{
    //创建一个应用程序对象
    //维护qt程序应用生命的一个对象,每个qt都有且只有一个
    QApplication a(argc, argv);
    
    //窗口类的一个对象
    learnQt w;
    
    //把窗口解释出来,窗口的show方法,显示窗口
    w.show();

    //a.exec()
    //死循环让程序一直运行,生命循环,消息循环
    /*
       while(1)
       {
       
       if(点击x) {berak;}
       if(点击最小化) {最小化;}
       }
    */
    return a.exec();//消息循环机制
}

learnqt.cpp

#include "learnqt.h"

learnQt::learnQt(QWidget *parent)
    : QWidget(parent)
{
}

learnQt::~learnQt()
{
}

learnqt.h

#ifndef LEARNQT_H
#define LEARNQT_H

#include <QWidget>//包含头文件的Qwidget文件

class learnQt : public QWidget
{
    //宏,引入qt信号和槽的一个宏
    Q_OBJECT

public:
    //parent 窗口指针,父窗口对象的指针
    //如果parent为0或者nullptr,表示当前窗口对象是个顶层窗口
    //顶层窗口就是在任务栏可以找到
    learnQt(QWidget *parent = nullptr);//默认构造
    ~learnQt();//析构函数
};
#endif // LEARNQT_H

.pro文件

QT       += core gui  //Qt包含的模块

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets//大于4版本以上,包含widgets模块

CONFIG += 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

SOURCES += \   //源文件
    main.cpp \
    learnqt.cpp

HEADERS += \  //头文件
    learnqt.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path)
: INSTALLS += target

Qt快捷键

  • 注释 ctrl+/
  • 运行 ctrl+r
  • 编译 ctrl+b
  • 自动对齐 ctrl+i
  • 帮助文档
    • F1
    • 左侧按钮
    • 对应文件夹的帮助文档"Qt\6.2.2\mingw_64\bin\assistant.exe"
posted @ 2022-02-06 21:39  圣道  阅读(77)  评论(0)    收藏  举报