当前位置:网站首页>Qt 信号在多层次对象间传递 多层嵌套类对象之间信号传递
Qt 信号在多层次对象间传递 多层嵌套类对象之间信号传递
2022-07-26 02:56:00 【恋恋西风】
一、先说需求:
可能是五层,或多层,子对象要发信号给第一层,这样,如果正常写很麻烦
二、解决方案:
专门拿 出一个类,做为中转类,中转类为单例;
子类,将信号 发给中转类,中转类,再发给写要的类;
上代码:
中转类:
#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;
}
想要上专信号 的对象
#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);
}
接收信号的对象
#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();
}
这样,不管是多少层,其实和二层没有区别了;
边栏推荐
- ES6高级-利用原型对象继承方法
- How to effectively prevent others from wearing the homepage snapshot of the website
- Pipnet: face key point detection for natural scenes "pixel in pixel net: directions efficient facial landmark detection in the wild"
- Arthas view the source code of the loaded class (JAD)
- MySQL(4)
- [introduction to C language] zzulioj 1006-1010
- Pinia plugin persist, a data persistence plug-in of Pinia
- 图像识别(七)| 池化层是什么?有什么作用?
- (PC+WAP)织梦模板蔬菜水果类网站
- Vofa+ serial port debugging assistant
猜你喜欢

【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(重构篇)

Turn on the LED

Application of shift distance and hypothesis

What if the test / development programmer gets old? Lingering cruel facts

Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation

massCode 一款优秀的开源代码片段管理器

MySQL tutorial: MySQL database learning classic (from getting started to mastering)

从各大APP年度报告看用户画像——标签,比你更懂你自己
![[纯理论] YOLO v4: Optimal Speed and Accuracy of Object Detection](/img/1f/f38c3b38feed9e831ad84b4bbf81c0.png)
[纯理论] YOLO v4: Optimal Speed and Accuracy of Object Detection

How to effectively prevent others from wearing the homepage snapshot of the website
随机推荐
scipy.sparse.vstack
Information System Project Manager - Chapter 10 communication management and stakeholder management examination questions over the years
Information system project managers must recite the core examination site (50). The contract content is not clearly stipulated
MySQL build websites data table
[translation] announce Vites 13
[C Advanced] deeply explore the storage of data (in-depth analysis + interpretation of typical examples)
MySQL(4)
(9) Attribute introspection
MySQL教程:MySQL数据库学习宝典(从入门到精通)
HLS Experiment 1 -- multiplier
Software testing post: Ali has three sides. Fortunately, he has made full preparations and has been offered
Be highly vigilant! Weaponization of smartphone location data on the battlefield
图像识别(六)| 激活函数
Convert rich text to normal text
How to design automated test cases?
[C language] deeply understand integer lifting and arithmetic conversion
Cycle and branch (I)
Exclusive interview with ringcentral he Bicang: empowering future mixed office with innovative MVP
Is it safe to open galaxy securities account by mobile phone?
Standardize your own debug process