当前位置:网站首页>QT signal transmission between multi-level objects signal transmission between multi-level nested class objects
QT signal transmission between multi-level objects signal transmission between multi-level nested class objects
2022-07-26 03:02:00 【Love the west wind】
One 、 First of all, demand :
It may be the fifth floor , Or multilayer , Sub objects should send signals to the first layer , such , It's troublesome to write normally
Two 、 Solution :
Specially take Make a class , As a transit class , The transfer class is a single example ;
Subclass , Will signal Send to transit class , Transit class , Then send it to the class you want ;
Code up :
Transit class :
#ifndef TRANSMITSIGNALS_H
#define TRANSMITSIGNALS_H
#include <QObject>
class TransmitSignals : public QObject
{
Q_OBJECT
public:
static TransmitSignals &GetInstance();
private:
TransmitSignals();
~TransmitSignals();
TransmitSignals(const TransmitSignals &) = delete;
TransmitSignals(const TransmitSignals &&) = delete;
TransmitSignals &operator=(const TransmitSignals &) = delete;
signals:
void sigReWriteOffsetRet(bool ret);
void sigFreedDragRet(bool ret);
void sigEndFreedDragRet(bool ret);
public slots:
};
#endif // TRANSMITSIGNALS_H
cpp
#include "transmitsignals.h"
TransmitSignals::TransmitSignals( )
{
}
TransmitSignals::~TransmitSignals( )
{
}
TransmitSignals& TransmitSignals::GetInstance()
{
static TransmitSignals RobotControl;
return RobotControl;
}
Want to go to college signal The object of
#include "form.h"
#include "ui_form.h"
#include "transmitsignals.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
connect(this, SIGNAL(send_test(bool)),&TransmitSignals::GetInstance(), SIGNAL(sigReWriteOffsetRet(bool)) );
}
Form::~Form()
{
delete ui;
}
void Form::on_pushButton_clicked()
{
emit send_test(true);
}
The object receiving the signal
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMovie>
#include <QDebug>
#include "transmitsignals.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&TransmitSignals::GetInstance(), SIGNAL(sigReWriteOffsetRet(bool)), this, SLOT(on_test_signal(bool)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_test_signal(bool ret)
{
qDebug()<<"on_pushButton_clicked";
}
void MainWindow::on_pushButton_clicked()
{
mForm.show();
}
such , No matter how many floors , In fact, it is no different from the second floor ;
边栏推荐
- GoLang 抽奖系统 设计
- (pc+wap) dream weaving template vegetable and fruit websites
- Zhimeng prompts you how to solve the problem of setting the field as linkage type
- Standardize your own debug process
- STM32 - serial port learning notes (one byte, 16 bit data, string, array)
- Code dynamically controls textview to move right (not XML)
- Difference between soft link and hard link
- 万维网、因特网和互联网的区别
- 织梦提示你设定了字段为联动类型如何解决
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
猜你喜欢

MySQL教程:MySQL数据库学习宝典(从入门到精通)

STM32 - DMA notes

多线程编程

How to design automated test cases?

Opening method of win11 microphone permission

Safety margin of mass consumption

File operation (I) -- File introduction and file opening and closing methods

FPGA_ Initial use process of vivado software_ Ultra detailed

Study notes of pytorch deep learning practice: convolutional neural network (Advanced)

Annotation development management third-party beans
随机推荐
如何根据登录测试的需求设计测试用例?
Longest Substring Without Repeating Characters
FPGA_ Initial use process of vivado software_ Ultra detailed
Image recognition (VII) | what is the pooling layer? What's the effect?
[NOIP2001 普及组] 最大公约数和最小公倍数问题
Eslint common error reporting set
ES6 advanced - using prototype object inheritance methods
Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?
VOFA+ 串口调试助手
Win11麦克风权限的开启方法
从各大APP年度报告看用户画像——标签,比你更懂你自己
STM32——串口学习笔记(一个字节、16位数据、字符串、数组)
I hope you can help me with MySQL
当点击Play以后,EditorWindow中的变量会被莫名其妙销毁.
文件操作(一)——文件简介与文件的打开方式和关闭
Arthas' dynamic load class (retransform)
MySQL build websites data table
图像识别(六)| 激活函数
Usage of arguments.callee
ShardingSphere数据分片