1.1 什么是Qt
Qt是一个跨平台的C++图形用户界面应用程序框架。它为应用程序开发者提供建立艺术级图形界面所需的所有功能。它是完全面向对象的,很容易扩展,并且允许真正的组件编程。
1.2 Qt发展史
1991年 Qt最早由奇趣科技开发
1996年 进入商业领域
2008年 奇趣科技被诺基亚公司收购,Qt称为诺基亚旗下的编程语言
2012年 Qt又被Digia收购
2014年 支持跨平台
1.3 Qt安装
https://blog.csdn.net/qq_23473839/article/details/80523318
1.4 Qt的框架
项目
------.pro
------头文件
-------.h
------源文件
--------main.cpp
--------.cpp
//main.cpp
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.exec();
return 0;
}
1.5 项目文件
#模块
QT += core gui
#高于4版本,添加QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#应用程序的名字
TARGET = demo
#指定makefile的类型,app
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 \
mywidget.cpp
#头文件
HEADERS += \
mywidget.h
1.6 第一个Qt程序
#include "mywidget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget w;
w.setWindowTitle("主要看气质");
w.show();
return a.exec();
}
1.7 父窗口与子窗口
每一个窗体都是一个父窗口,它不是其他任一个窗体的子窗口.窗体上的所有控件,按钮等就是窗体的子窗口。
1.8 信号和槽
信号槽是 Qt 框架引以为豪的机制之一。所谓信号槽,实际就是观察者模式。当某个事件发生之后,比如,按钮检测到自己被点击了一下,它就会发出一个信号(signal)。这种发出是没有目的的,类似广播。如果有对象对这个信号感兴趣,它就会使用连接(connect)函数,意思是,将想要处理的信号和自己的一个函数(称为槽(slot))绑定来处理这个信号。也就是说,当信号发出时,被连接的槽函数会自动被回调。这就类似观察者模式:当发生了感兴趣的事件,某一个操作就会被自动触发。(这里提一句,Qt 的信号槽使用了额外的处理来实现,并不是 GoF 经典的观察者模式的实现方式。)
1.9 坐标系统
以左上角为原点,X向右增加,Y向下增加。
对于嵌套窗口,其坐标是相对于父窗口来说的。