QT笔记01

一.Qt简介 

  1. QT是一个跨平台的C++图形用户界面应用程序框架
  2. 优点:跨平台,接口简单、易上手,一定程度简化了内存回收

二.创建第一个QT程序

  1.  点击创建项目后,设置相关路径和项目名称;
  2. 注意:名称不能有中文,不能有空格,路径不能有中文;
  3. 默认创建有窗口类,myWidget,基类有三种选择: QWidget 、QMainWindow、QDialog
  4. main函数
  5. 工程文件 .pro    它是qmake自动生成的用于生产makefile的配置文件  
  6. 头文件
#include "widget.h"

#include <QApplication>//包含一个应用程序类的头文件

//main程序入口 argc命令行变量的数量  argc命令行变量的数组
int main(int argc, char *argv[])
{
    //a 应用程序对象 在Qt中,应用程序对象有且仅有一个
    QApplication a(argc, argv);
    //窗口对象 Widget父类 ->Qwidget 空窗口
    Widget w;
    //窗口对象默认不会显示,必须要调用show方法显示窗口
    w.show();
    //让应用程序对象进入消息循环  
    //让代码阻塞到这行
    return a.exec();
}
QT       += core gui  //Qt包含的模块

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

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 \
    widget.cpp

HEADERS += \
    widget.h

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

#include <QWidget>//包含头文件 QWidget 窗口类

class Widget : public QWidget//继承
{
    Q_OBJECT      //宏,允许类中使用信号和槽的机制

public:
    Widget(QWidget *parent = nullptr);//有参构造
    ~Widget();//析构函数
};
#endif // WIDGET_H

 

#include "widget.h"
//命名规范
//类名 首字母大写,单词和单词之间首字母大写
//函数名 变量名称 首字母小写,单词和单词之间首字母大写

//快捷键
//注释 ctrl+/
//运行 ctrl+r
//编译 ctrl+b
//字体缩放 ctrl+鼠标滚轮
//查找 ctrl+f
//整行移动 ctrl+shift+↑/↓
//帮助文档 F1
//自动对齐 ctrl+i
//同名之间的.h和.cpp切换 F4

//帮助文档 第一种方式 F1  第二种 左侧按钮   D:\QT\5.14.0\mingw73_64\bin

Widget::Widget(QWidget *parent)
    : QWidget(parent)     //初始化列表
{
}

Widget::~Widget()
{
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值