如何使用 signals.boostv2 调用特定插槽
How call o specific slot with signals.boostv2
我开发过一个依赖于发布者订阅者的应用程序(使用 boost.signalsv2(
这是控制器;
#include "view.hpp"
class Controller
{
boost::signals2::signal<void ()> sig;
public:
Controller() {
}
void subscribe(listener& listener) {
// Signal with no arguments and a void return value
sig.connect(boost::bind(&listener::OnUpdate, &listener));
}
void DoWork() const {
// Call all of the slots
sig();
}
void Update();
};
doWork 函数调用所有订阅槽。
int main() {
Controller c;
View l1, l2;
c.subscribe(l1);
std::cout << "One subscribed:n";
c.DoWork();
c.subscribe(l2);
c.subscribe(l3);
std::cout << "nBoth subscribed:n";
c.DoWork();
}
有多个订户系统。(L1、L2 和 L3( 我想发布特定的一个 (l2( 我该如何检查并执行此操作?
这不是它的意图。如果要区分,请使用不同的信号或将令牌传递给处理程序,以便它们能够知道它们是否对该特定事件感兴趣。
如果您希望在连接的处理程序列表中有一个特定的/position/来获取事件,那么您可以使用替代/自定义组合器:https://www.boost.org/doc/libs/1_73_0/doc/html/signals2/thread-safety.html#id-1.3.36.7.3
相关文章:
- QT 插槽未在主线程上调用
- Qt信号和插槽如果从QRunnable或其他线程调用,则不起作用
- Qt插槽调用了两次
- 从插槽调用 QApplication::p rocessEvents 会导致再次调用同一插槽
- 如何使用 signals.boostv2 调用特定插槽
- 通过 id 访问 QML 插槽中的嵌套对象(从 c++ 调用)
- 当再次触发信号时,从Qt插槽执行的功能被第二次调用时会发生什么?
- 插槽调用了两次qt
- QListView 的插槽::d ouble点击未被调用
- 类继承自QLabel,为什么不调用自定义插槽?
- 为什么插槽函数即使成功调用也无法插入文本
- 有没有办法调试排队等待对象的Qt插槽调用
- 当对话框中的任何小部件发出信号时,是否可以调用插槽
- 这是在Qt信号和插槽中使用参数调用函数的好方法吗?
- 从第二个线程调用Qt信号有效 - >对连接的插槽没有影响
- 通过插槽打印/显示QT函数调用的内容
- Qt插槽调用两次
- 调用未连接的Qt插槽.调用未连接的
- QT小部件插槽调用没有被单独的线程信号激活
- Qt队列连接中的插槽调用顺序