什么是信号和插槽? [英] What are signals and slots?
问题描述
有人可以用简单的术语解释信号和槽位模式吗?
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屋!