当前位置:网站首页>QT signal and slot
QT signal and slot
2022-07-06 22:40:00 【There is a mess of code】
List of articles
Tips : Here you can add a list of all the articles in the series , The directory needs to be added manually
for example : Chapter one Python Introduction to machine learning pandas Use
Tips : After writing the article , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
Preface
Tips : Here you can add the general content to be recorded in this article :
for example : With the development of artificial intelligence , Machine learning is becoming more and more important , A lot of people have turned on learning machine learning , This paper introduces the basic content of machine learning .
Tips : The following is the main body of this article , The following cases can be used for reference
One 、 Signals and slots
Signals and slots are used for communication between objects , It is similar to the interface address between the back end and the front end .
The signal is sent by the sender , The slot can be regarded as the receiver
The signal and slot are QT Unique signal transmission mechanism , He can make contact with objects that do not interfere with each other
utilize connect Function creation
The essence of a slot is a member function of a class , Its parameters can be of any type and C++ Member functions make no difference . It can be a virtual function , Can also be overloaded ,
The only difference is that the slot can be connected with the signal ,, Whenever the signal connected to the slot is sent, it will call the slot
You can also send signals , Then do the corresponding operation before sending to the slot
Characteristics of signal :
Ordinary function , There is no need to achieve , Use signal Keyword declaration , You can customize the signal , no return value , With parameters , Can be suitable for use emit Keywords send signals
Characteristics of grooves
Customizable slot function
Slot function has no return value
With parameters
Two 、 Connect
1、QT4
Through macro
SIGNAL SLOT
SLGNAL()/SLOT Two Hongjiang functions rotate -> character string
connect(sender,SLGNAL(sig1(int,double,QString)),receiver,SLOT(sil1(int,doublemQString)))
shortcoming Error checking will not be done during compilation
2、QT5
The function address used by the signal slot
connect(sender,&Sender::sig1,receiver,&Receiver::slot1)
advantage During compilation, the function type , Check the number
The code is as follows ( Example ):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
Four 、 matters needing attention
The signal / The number of slot function parameters can be different
The number of slot function parameters can be less than the number of signal parameters
Irreversible
5、 ... and 、 Expand
Signals can be connected to signals
One signal can connect multiple slot functions
A slot function can be connected by multiple signals at the same time
Slot functions can be used lambda expression
After the signal slot is connected , Can be disconnected disconnect
The following is written in the main function , Other creation items are automatically added , Just copy the following code to the main cpp Just fine
The sample code be based on QT4
#include "widget.h"
#include <QPushButton>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QPushButton *btn = new QPushButton("adsdadww ",this);
btn->show();
btn->resize(50,50);
btn->move(60,60);
resize(600,400);
QPushButton *btn2 = new QPushButton("slfeofs",this);
btn2->show();
btn2->resize(80,30);
btn2->move(100,100);
this->zt = new Teacher(this);
this->st = new Student(this);
connect(btn2,SIGNAL(clicked()),zt,SIGNAL(hungry()));
connect(zt,SIGNAL(hungry()),st,SLOT(treat()));
connect(btn2,SIGNAL(clicked()),this,SLOT(close()));
st->treat();
setWindowTitle("sdawadwd");
setFixedSize(600,400);
//connect(st,SLOT(treat()));
}
void Widget::classIsOver(){
}
Widget::~Widget()
{
}
be based on QT5 Code for
#include "mainwindow.h"
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QPushButton *btn = new QPushButton("adsdadww ",this);
btn->show();
btn->resize(50,50);
btn->move(60,60);
resize(600,400);
QPushButton *btn2 = new QPushButton("slfeofs",this);
btn2->show();
btn2->resize(30,30);
btn2->move(100,100);
connect(btn2,&QPushButton::clicked,this,&MainWindow::close);
setWindowTitle("sdawadwd");
setFixedSize(600,400);
}
MainWindow::~MainWindow()
{
}
边栏推荐
- UDP programming
- OpenSSL:适用TLS与SSL协议的全功能工具包,通用加密库
- SQL Server生成自增序号
- signed、unsigned关键字
- MySQL ---- first acquaintance with MySQL
- 金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)
- Should novice programmers memorize code?
- Unity3d minigame unity webgl transform plug-in converts wechat games to use dlopen, you need to use embedded 's problem
- Gd32f4xx serial port receive interrupt and idle interrupt configuration
- GD32F4XX串口接收中断和闲时中断配置
猜你喜欢
Aardio - 通过变量名将变量值整合到一串文本中
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
(18) LCD1602 experiment
剑指offer刷题记录1
基于 QEMUv8 搭建 OP-TEE 开发环境
Mysql 身份认证绕过漏洞(CVE-2012-2122)
The SQL response is slow. What are your troubleshooting ideas?
Daily question 1: force deduction: 225: realize stack with queue
Aardio - construct a multi button component with customplus library +plus
随机推荐
Uniapp setting background image effect demo (sorting)
雅思口语的具体步骤和时间安排是什么样的?
Sizeof keyword
That's why you can't understand recursion
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
hdu 5077 NAND(暴力打表)
Classification, function and usage of MySQL constraints
Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
return 关键字
The SQL response is slow. What are your troubleshooting ideas?
剪映+json解析将视频中的声音转换成文本
poj 1094 Sorting It All Out (拓扑排序)
2022-07-05 使用tpcc对stonedb进行子查询测试
Improving Multimodal Accuracy Through Modality Pre-training and Attention
Mysql database basic operations DML
On the problems of born charge and non analytical correction in phonon and heat transport calculations
Signed and unsigned keywords
case 关键字后面的值有什么要求吗?
Daily question 1: force deduction: 225: realize stack with queue
Gd32f4xx serial port receive interrupt and idle interrupt configuration