当前位置:网站首页>QT tutorial: creating the first QT program
QT tutorial: creating the first QT program
2022-07-07 00:26:00 【Cheems_ Pak Choi】
One 、 Leading knowledge
1、 The base class represents the parent class 、 Derived classes represent subclasses
2、 Base class QWidget yes QDialog and QMainWindow Parent class of
3、 If you create one, you need to have a menu bar 、 The toolbar 、 Status bar, etc. , You can choose QMainWindow As the base class
4、QDialog As a base class , It's just a simple dialog , There is only one close button in the upper right corner x
Two 、 After the project is successfully created, the code is as follows
1、main.cpp in
#include “mywidget . h” // The class name is the same as the header file name
#include
// Application entry
int main(int argc , char * argv [ ])
{
QApplication a (argv , argv);//QApplication Represents the application class , In every one of them qt There is and only one in the program
MyWidget w;//MyWidget Represents a window class ( After the window class is created, it is not displayed by default , So we'll show it later ),w Represents the object that created a window class
w . show();// Show window ,w It refers to the whole window , When we do other operations on this window , It is equivalent to operating it
return a . exec(); // Cycle through the window , When a trigger signal or event is received , It will jump out , For example, when closing a window , It will jump out of this cycle
}
2、mywidget.h in
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include
class MyWidget( Subclass ) : public QWidget ( Parent class )
{
Q_OBJECT // If signal and slot mechanisms are used , You must add this macro
public :
MyWidget (QWidget *parent = 0) ;// Constructors
~MyWidget(); // Destructor
};
#endif
3、mywidget.cpp in
#include “mywidget.h”
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
}
MyWidget::~MyWidget()
{
}
4、xxxxx.pro In Engineering
QT += core gui //qt Modules used in the program
greaterThan(QT_MAJOR_VERSON,4): QT += widgets // For compatibility with previous versions
TARGET = xxxxx // Generated application name
TEMPLATE = app // Specify the generated makefile The type of lib
SOURCE +=main.cpp
mywidget.cpp // Source file
HEADERS +=mywidget.h // The header file
5、 If a new window needs to be attached to another window , You need to specify a parent class for this window ( It means that the new window is not independent , Instead, it is built in the parent window )
6、QT After creating pointer in , The condition that memory can be recycled automatically
1) from QObject Derived classes :1. direct 2. indirect
2) Specify the parent class , When father deconstructs , First analyze its child paper
边栏推荐
- js导入excel&导出excel
- 2022/2/10 summary
- 2022/2/11 summary
- VTK volume rendering program design of 3D scanned volume data
- PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
- 工程师如何对待开源 --- 一个老工程师的肺腑之言
- 【vulnhub】presidential1
- Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
- C language input / output stream and file operation [II]
- Geo data mining (III) enrichment analysis of go and KEGG using David database
猜你喜欢
On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
沉浸式投影在线下展示中的三大应用特点
量子时代计算机怎么保证数据安全?美国公布四项备选加密算法
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Pytest multi process / multi thread execution test case
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Devops can help reduce technology debt in ten ways
The difference between redirectto and navigateto in uniapp
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
随机推荐
智能运维应用之道,告别企业数字化转型危机
Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
DAY TWO
Interface joint debugging test script optimization v4.0
Geo data mining (III) enrichment analysis of go and KEGG using David database
vector的使用方法_vector指针如何使用
PDF文档签名指南
Use Yum or up2date to install the postgresql13.3 database
微信小程序uploadfile服务器,微信小程序之wx.uploadFile[通俗易懂]
SQL的一种写法,匹配就更新,否则就是插入
DAY TWO
谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
openresty ngx_ Lua subrequest
PostgreSQL高可用之repmgr(1主2从+1witness)+Pgpool-II实现主从切换+读写分离
509 certificat basé sur Go
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
GPIO簡介
使用源码编译来安装PostgreSQL13.3数据库
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
[automated testing framework] what you need to know about unittest