当前位置:网站首页>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
边栏推荐
- DAY TWO
- The difference between redirectto and navigateto in uniapp
- [vector retrieval research series] product introduction
- [CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
- How engineers treat open source -- the heartfelt words of an old engineer
- Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
- 使用yum来安装PostgreSQL13.3数据库
- PostgreSQL uses pgpool II to realize read-write separation + load balancing
- Pinia module division
- 一图看懂对程序员的误解:西方程序员眼中的中国程序员
猜你喜欢
Core knowledge of distributed cache
48 page digital government smart government all in one solution
2022/2/10 summary
工程师如何对待开源 --- 一个老工程师的肺腑之言
DAY FOUR
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
37 page overall planning and construction plan for digital Village revitalization of smart agriculture
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
Clipboard management tool paste Chinese version
随机推荐
Interface joint debugging test script optimization v4.0
What can the interactive slide screen demonstration bring to the enterprise exhibition hall
准备好在CI/CD中自动化持续部署了吗?
Why should a complete knapsack be traversed in sequence? Briefly explain
2021 SASE integration strategic roadmap (I)
SQL的一种写法,匹配就更新,否则就是插入
Supersocket 1.6 creates a simple socket server with message length in the header
Rails 4 asset pipeline vendor asset images are not precompiled
Quickly use various versions of PostgreSQL database in docker
Business process testing based on functional testing
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
AVL树到底是什么?
DAY TWO
37 page overall planning and construction plan for digital Village revitalization of smart agriculture
【向量检索研究系列】产品介绍
Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
[automated testing framework] what you need to know about unittest
DAY SIX
How about the order management of okcc call center