基于信号槽的简单管理类
a simple management based on Signals and Slots
本项目旨在提供一个第三方信号槽管理类以减少模块间的耦合,使信号槽的连接分为两步进行,通过注册主题和订阅的方式更灵活的使用信号槽。
This project aims to provide a third-party Signals & Slots management class to reduce the coupling between modules, so that the Signals & Slots connection is divided into two steps, and the Signals & Slots is more flexible by registering the subject and subscription.
仅支持使用SIGNAL/SLOT宏语法的信号槽
Only Signals & Slots using the SIGNAL/SLOT macros syntax are supported
-
获取QtSignalSlotManager实例,QtSignalSlotManager使用了单例模式,使用时通过
QtSignalSlotManager::getInstance()
即可得到QtSignalSlotManager实例。 -
添加主题/移除主题
void addSubject(int subjectId, QObject *sender, const char *signal);
void removeSubject(int subjectId, QObject *sender, const char *signal);
- 订阅/取消订阅
void subscribe(int subjectId, QObject *receiver, const char *slot);
void unsubscribe(int subjectId, QObject *receiver, const char *slot);
-
添加/移除主题 与 订阅/取消订阅 没有操作顺序限制,即可以先注册主题后订阅,反之亦然。
-
具体示例可参考 Demo
Get the QtSignalSlotManager instance. QtSignalSlotManager uses the singleton mode. You can get the QtSignalSlotManager instance by using
QtSignalSlotManager::getInstance()
.Add subject/Remove subject
void addSubject(int subjectId, QObject *sender, const char *signal); void removeSubject(int subjectId, QObject *sender, const char *signal);
- Subscribe/Unsubscribe
void subscribe(int subjectId, QObject *receiver, const char *slot); void unsubscribe(int subjectId, QObject *receiver, const char *slot);
Add/Remove subject and Subscribe/Unsubscribe There is no order restriction, that is, you can add a subject and then subscribe, and vice versa.
More detail see Demo.