第一个QT项目笔记

第一个QT

下载地址:https://www.qt.io/download-open-source

UTOOLS1592481283123.png

打开 Qt Creator 界面选择 New Project 或者选择菜单栏 【文件】 -【新建文件或项目】 菜单项

NmNNgf.png

弹出 New Project 对话框,选择 Application,选择 Qt Widgets Application ,选择 Choose 按钮, 弹出如下对话框

NmUAsS.png

设置项目名称和路径,按照向导进行下一步,

NmO8C4.png

选择编译套件

NmH60O.png

向导会默认添加一个继承自 CMainWindow 的类,可以在此修改类的名字和基类。 默认的基类有 QMainWindow、 QWidget 以及 QDialog 三个,我们可以选择 QWidget(类似于空窗口)

NmUvlV.png

系统会默认给我们添加 文件 和一个.pro项目文件,点击完成, 即可创建出一个 Qt 桌面程序。

NmaKTH.png

点击运行,马上就要看见成功了

Nma0ts.png

为绿色就成功了,这也是成功男士看破红尘的时候,既然绿了自然就有结果了

NmdENj.png

这就是成功的结果,现在就是看看结果的准确性了(做一下亲子鉴定)

NmdlbF.png

分析一下代码:

myqt.pro 工程文件(project),它是 qmake 自动生成的用于生产 makefile 的配置文件

#-------------------------------------------------
#
# Project created by QtCreator 2020-06-18T17:23:42
#
#-------------------------------------------------

# 包含的模块
QT       += core gui

# 大于 Qt4 版本才包含 widget 模块
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

# 应用程序名 生成的.exe 程序名称
TARGET = myqt

# 模板类型 应用程序模板
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as 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


# 源文件
SOURCES += \
        main.cpp \
        widget.cpp

# 头文件
HEADERS += \
        widget.h
# .ui 设计文件
FORMS += \
        widget.ui

main.cpp

#include "widget.h"

//标准类名声明头文件没有.h 后缀
#include <QApplication>

int main(int argc, char *argv[])
{
    // 应用程序类
    QApplication a(argc, argv);

    //MyWidget对象
    Widget w;


    w.show();

    //程序进入消息循环
    return a.exec();
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

widget.h 头文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    Ui::Widget *ui;
};

#endif // WIDGET_H

QT的所有代码都已经同步在gitee中,并持续更新。

由于个人水平有限, 难免有些错误, 希望各位点评

@Author: cpu_code

@Date: 2020-06-11 20:24:20

@LastEditTime: 2020-06-11 20:26:09

@FilePath: \QT\firstQt\main.cpp

@Gitee: https://gitee.com/cpu_code

@Github: https://github.com/CPU-Code

@CSDN: https://blog.csdn.net/qq_44226094

@Gitbook: https://923992029.gitbook.io/cpucode/

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

极客程序设计

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

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

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

打赏作者

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

抵扣说明:

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

余额充值