您的位置:首页 > 编程语言 > Qt开发

QT5.10开发(2)QT入门了解及Demo介绍笔记

2018-01-18 11:03 676 查看

什么是QT

QT是一个跨平台C++图形用户界面应用类库框架。也就是GUI编程。当前最新版本5.10.

支持的平台

windows

linux

mac

ios

android

QT的优点

跨平台

接口简单,容易上手

简化了内存回收机制

开发效率高

可以进行嵌入式开发

QT模块



Demo创建

下载安装完毕QT Creater 打开创建QT项目:









创建完毕点击运行



运行结果



Demo介绍

#include "mainwindow.h"

//QApplication 应用程序类
//QT头文件没有.h
//头文件和类名一样
#include <QApplication>

/*main是应用程序入口*/
int main(int argc, char *argv[])
{
//有且只有一个应用程序类的对象
QApplication a(argc, argv);

//MainWindow 是程序帮我创建一个窗口类。所有继承QWidget类都是窗口类。
MainWindow w;

//显示窗口
w.show();

// a.exec(); 让程序一直执行,等待用户操作,也就是等待事件操作。
return a.exec();
}


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

/*
* class MainWindow : public QMainWindow
* MainWindow 继承 QMainWindow
* class Q_WIDGETS_EXPORT QMainWindow : public QWidget
* QMainWindow 继承 QWidget
*/
class MainWindow : public QMainWindow
{
Q_OBJECT //信号与槽的时候使用

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

#endif // MAINWINDOW_H


#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
}

MainWindow::~MainWindow()
{

}


项目文件

#-------------------------------------------------
#
# Project created by QtCreator 2018-01-18T10:22:04
#
#-------------------------------------------------
# 添加模块
QT       += core gui

# 兼容其他QT版本
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

#应用程序名称
TARGET = Demo
#指定makefile的类型 类型:app 、 lib
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.
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 \
mainwindow.cpp

#头文件
HEADERS += \
mainwindow.h
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt qt5 入门demo demo QT模块
相关文章推荐