C++ Qt引擎 (1)初学创建QT项目

5 篇文章 0 订阅

初学Qt,Qt应用程序开发框架

QT助手:QT中所包含的类、函数等的查询工具

xx:\Qt\Qt5.9.8\5.9.8\mingw53_32\bin\assistant.exe

 

一、创建Qt项目

1、  启动目录

安装QT后,无法找到QT启动的位置,启动qtcreator.exe,目录如下:

安装的盘符:\Qt\Qt5.9.8\Tools\QtCreator\bin\qtcreator.exe

2、启动QT后,新建项目

(1)点击创建项目按钮

(2)选择模板(Application 应用、QT Widgets Application QT空窗体应用程序)

(3)填写项目名称及选择项目路径

(4)编译器选择,如果之前安装时选择VS的,可以在此处选择VS2017或2015或2013等

(5)选择类,Widget为空窗口,MainWindow (主窗口)和Dialog(对话框)是Widget的派生类

MainWindow中包含菜单栏、工具栏、状态栏

Dialog包含确定及取消按钮

(6)类名首字母大写

(7)版本控制系统(代码同步工具),例如SVN、GIT

 

二、Qt项目创建后,各个文件详细内容记录

1、xxx.pro文件  项目文件

#-------------------------------------------------
#                    创建项目名称 及 创建项目时间
# Project created by QtCreator 2021-02-19T12:58:28
#
#-------------------------------------------------
# 为QT添加模块  core QT核心模块 gui 图形用户界面模块
QT       += core gui

#4.0以后的版本  添加widgets模块
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

#生成的.exe应用程序 名字
TARGET = QTCreateProjectOne
#使用的模板
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has 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.
#定义选项添加 QT宏 QT_DEPRECATED_WARNINGS当API过时时,编译器提示警告
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

#支持C++ll新特性  实时更新
CONFIG += c++11

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

2、Qt各个模块及功能概况

3、头文件

#ifndef WIDGET_H
#define WIDGET_H

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

class Widget : public QWidget
{
    Q_OBJECT//支持信号 和 槽

public:
    Widget(QWidget *parent = 0);//析构函数
    ~Widget();//析构函数
};

#endif // WIDGET_H

4、Main函数 类文件

main.cpp

#include "Widget.h"
#include <QApplication>//应用程序头文件

/*
 * QT编辑器快捷键
 * 注释  ctrl+/
 * 转到定义或声明切换  F2
 * 上一步、下一步  alt+← alt+→
 *
 * 运行  ctrl+R
 * 构建  ctrl+B
 * */

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);//定义应用程序对象
    Widget w;//定义空窗口对象
    w.show();//调用空窗口子函数,显示窗口

    return a.exec();//调用应用程序对象 消息循环函数
}

Widget.cpp

#include "Widget.h"

//构造函数
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //记忆接口
    this->setWindowTitle("设置窗口标题");//设置窗口标题
    this->resize(400, 500);//设置窗口大小,宽、高
    this->setFixedSize(200, 200);//设置固定窗口大小,窗口不能拖拽改变大小
}

//析构函数
Widget::~Widget()
{

}

 

 

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值