什么是信号和插槽? [英] What are signals and slots?

查看:190
本文介绍了什么是信号和插槽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以简单地用信号和插槽模式来解释吗?

Can someone explain in simple terms the "signals and slots" pattern?

推荐答案

信号和插槽是一种解耦的方式发送者(信号)和零个或多个接收器(时隙)。假设您是一个系统,其中有一些事件要提供给对这些事件感兴趣的系统的任何其他部分。而不是将生成事件的代码硬编码到想要了解这些事件的代码,您将使用信号和插槽模式。

Signals and slots are a way of decoupling a sender (the signal) and zero or more receivers (the slots). Let's say you a system which has events that you want to make available to any other part of the system interested in those events. Rather than hard-wiring the code that generates event to the code that wants to know about those events, you would use a signals and slots pattern.

当发送方发信号事件(通常通过调用与该事件/信号相关的功能),将自动调用该事件的所有接收器。这使您可以在程序生命周期中根据需要连接和断开接收器。

When the sender signals an event (usually by calling the function associated with that event/signal) all the receivers for that event are automatically called. This allows you to connect and disconnect receivers as necessary during the lifetime of the program.

由于这个问题被标记为C ++,所以这里是 Boost.Signals 库,其中有更详尽的解释。

Since this question was tagged C++, here is a link to the Boost.Signals library which has a much more thorough explanation.

这篇关于什么是信号和插槽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆