当前位置: 首页 > wzjs >正文

网站主机空间价格做网站学什么专业

网站主机空间价格,做网站学什么专业,销售网络平台,电商网站开发背景信号槽连接方法对比 1. 直接连接2. 集中管理3.函数指针初始化列表后期需要disconnect 对比 1. 直接连接 connect(codeWindow, &CodeEditorWindow::SetBaseLineSignal, monitoringWindow, &MonitoringWindow::SetBaseLineSlot),connect(&ButtonTree::Instance(), &a…

信号槽连接方法对比

  • 1. 直接连接
  • 2. 集中管理
  • 3.函数指针+初始化列表
    • 后期需要disconnect
  • 对比

1. 直接连接

 connect(codeWindow, &CodeEditorWindow::SetBaseLineSignal, monitoringWindow, &MonitoringWindow::SetBaseLineSlot),connect(&ButtonTree::Instance(), &ButtonTree::Function,
this, &UI::Function),
connect(&ButtonTree::Instance(), &ButtonTree::LeftClicked,
this, &UI::LeftClicked),connect(parSearchdialog, &SearchDialog::SearchRequested, 
parWindow, &ParametersWindow::FocusOnLineEditByIndex),

2. 集中管理

// SignalBinder.h
#ifndef SIGNALBINDER_H
#define SIGNALBINDER_H#include <QObject>
#include <vector>/*** 绑定描述结构:sender, signal, receiver, slot*/
struct SignalBinding {QObject*    sender;const char* signal;QObject*    receiver;const char* slot;
};/*** SignalBinder:批量自动 connect 信号与槽*/
class SignalBinder {
public:/*** 批量绑定所有描述的信号–槽对*/static void bindAll(const std::vector<SignalBinding>& bindings) {for (const auto& b : bindings) {bool ok = QObject::connect(b.sender, b.signal,b.receiver, b.slot);if (!ok) {qWarning("SignalBinder: connect failed %s -> %s", b.signal, b.slot);}}}
};#endif // SIGNALBINDER_H
// UI.cpp
#include "SignalBinder.h"void UI::ConfigSignalsSlot() {// 定义所有待绑定的四元组static const std::vector<SignalBinding> bindings = {{ codeWindow,                 SIGNAL(SetBaseLineSignal(QString)),    monitoringWindow,    SLOT(SetBaseLineSlot(QString)) },{ &ButtonTree::Instance(),    SIGNAL(Function(QString)),             this,                SLOT(Function(QString))       },{ &ButtonTree::Instance(),    SIGNAL(LeftClicked(QString)),          this,                SLOT(LeftClicked(QString))    },{ parSearchdialog,            SIGNAL(SearchRequested(int)),          parWindow,           SLOT(FocusOnLineEditByIndex(int)) },// ... 后续模块只需再添加一行即可};// 一次性完成所有信号–槽绑定SignalBinder::bindAll(bindings);
}

3.函数指针+初始化列表

void UI::ConfigSignalsSlot()
{// 用一个 std::initializer_list 执行所有 connect,返回的 QMetaObject::Connection 会被丢弃// (如果你需要 later disconnect,就把它们保存到成员变量里)[[maybe_unused]] const auto connections = std::initializer_list<QMetaObject::Connection>{// codeWindow::SetBaseLineSignal(QString) -> monitoringWindow::SetBaseLineSlot(QString)connect(codeWindow,&CodeEditorWindow::SetBaseLineSignal,monitoringWindow,&MonitoringWindow::SetBaseLineSlot),// ButtonTree::Function(QString) -> UI::Function(QString)connect(&ButtonTree::Instance(),&ButtonTree::Function,this,&UI::Function),// ButtonTree::LeftClicked(QString) -> UI::LeftClicked(QString)connect(&ButtonTree::Instance(),&ButtonTree::LeftClicked,this,&UI::LeftClicked),// SearchDialog::SearchRequested(int) -> ParametersWindow::FocusOnLineEditByIndex(int)connect(parSearchdialog,&SearchDialog::SearchRequested,parWindow,&ParametersWindow::FocusOnLineEditByIndex),// ……后续所有绑定都放这里即可……};// (void)connections; // 如果编译器抱 unused warning,就这样显式丢弃
}

后期需要disconnect

1.在类里用一个成员容器保存连接句柄

// UI.h
class UI : public QObject {// ...
private:std::vector<QMetaObject::Connection> m_connections;void ConfigSignalsSlot();void disconnectAllSignals();
};
  1. 生成连接时把返回值 push_back 到这个容器
// UI.cpp
void UI::ConfigSignalsSlot()
{// 先断掉旧的disconnectAllSignals();// 然后重新连接,并把每个 QMetaObject::Connection 存下来m_connections.push_back(connect(codeWindow,&CodeEditorWindow::SetBaseLineSignal,monitoringWindow,&MonitoringWindow::SetBaseLineSlot));m_connections.push_back(connect(&ButtonTree::Instance(),&ButtonTree::Function,this,&UI::Function));m_connections.push_back(connect(&ButtonTree::Instance(),&ButtonTree::LeftClicked,this,&UI::LeftClicked));m_connections.push_back(connect(parSearchdialog,&SearchDialog::SearchRequested,parWindow,&ParametersWindow::FocusOnLineEditByIndex));// …如果有更多绑定,继续 push_back…
}

3.断开所有/部分连接

void UI::disconnectAllSignals()
{for (auto& c : m_connections)QObject::disconnect(c);m_connections.clear();
}

对比

方式关键特点可维护性类型安全运行时开销
SIGNAL/SLOT 宏字符串化,运行时匹配较差,需要手动对照无(仅运行时错误)轻微
SignalBinder + 字符串表集中管理,少写重复代码中等,只要维护描述表无(仍是字符串)少量循环开销
函数指针 + initializer_list编译期检查、集中绑定、一行一对最好,所有绑定尽在一处最好,编译期类型安全零额外,编译期展开

文章转载自:

http://DJ3ysZr8.LjLLt.cn
http://yBJkIL4l.LjLLt.cn
http://mTkfUSyt.LjLLt.cn
http://lPiVaiH1.LjLLt.cn
http://W33z6tOf.LjLLt.cn
http://HYoqhFFD.LjLLt.cn
http://AmqdDn22.LjLLt.cn
http://EXBxxV4Q.LjLLt.cn
http://2tFeMuqd.LjLLt.cn
http://857ynuZo.LjLLt.cn
http://skH36PKU.LjLLt.cn
http://ZcPgNg3H.LjLLt.cn
http://V0wW8hNs.LjLLt.cn
http://G7xhY3lM.LjLLt.cn
http://Dbpzo7s2.LjLLt.cn
http://aepGq6bc.LjLLt.cn
http://X5CBsJnJ.LjLLt.cn
http://UmF8sIgG.LjLLt.cn
http://SYMdumNR.LjLLt.cn
http://wvoUlQoO.LjLLt.cn
http://9ujuyUIr.LjLLt.cn
http://3XSgEj5B.LjLLt.cn
http://oWv3AiZb.LjLLt.cn
http://dnlLQVaZ.LjLLt.cn
http://Fzi39iYV.LjLLt.cn
http://9bU7GhBT.LjLLt.cn
http://zOrU2En5.LjLLt.cn
http://pszy8Jki.LjLLt.cn
http://pjTZbiZ5.LjLLt.cn
http://kYxytWUp.LjLLt.cn
http://www.dtcms.com/wzjs/678877.html

相关文章:

  • 江苏省住建厅官方网seo怎么刷关键词排名
  • 哪个网站做图找图片石家庄装修公司排名
  • 手机网站开发存储数据百度地图排名可以优化吗
  • 开发网站需要注意的安全问题萍乡网站设计公司
  • 电子商务网站建设市场分析手游平台
  • 凤台做网站南通市住房和城乡建设厅网站
  • wordpress软件网站模板下载photoshop免费素材库
  • 网站建设维护 天博网络柳州建设公司网站
  • 唐山网站建设方案咨询企业网络营销目标
  • 电子商务网站建设的主要内容性价比最高的网站建设
  • 音乐网站开发文档网站设计展示
  • 专业网站设计开发公司html登录注册页面代码
  • 邯郸网站设计徐州人才网前程无忧
  • 赣榆建设局网站如何用ps做网站
  • 网站设置怎么删除免费公司网址
  • 网站底色什么颜色好看免费的库存管理软件有哪些
  • 网站开发jsp 很少杭州seo优化公司
  • 广东省住房和城乡建设部网站企业类网站
  • 河北建设网站首页组态王如何做网站链接
  • 景翔物流网站建设公司做门户网站多少钱
  • 网站建设现状调查研究wordpress英文版下载地址
  • wordpress模板网站软件设计师中级
  • 能够做数据地图的网站网站模板尺寸
  • 网站制作好学吗交通网上服务平台
  • 首都开发公司东莞seo建站咨询
  • 网站建设及推广费用什么网站做电脑系统好
  • houzz室内设计wordpress配置搜索引擎优化
  • 专门做图标的网站深圳做网站推广
  • 网站建设 引导沧州网站建设熊掌号
  • 网站开发项目人员安排wordpress浮动视频