sigslot.h的使用
来源:互联网 发布:dota2网络连接不上 编辑:程序博客网 时间:2024/05/01 02:40
sigslot.h的获取路径:http://share.weiyun.com/0c1b5303ff4c3ea5ba9ce3de4a333eb2
可用于两个类之间的相互调用
#include "stdafx.h"
#include "sigslot.h"class AAA{public:sigslot::signal1<string> Onput;sigslot::signal2<int, int> OnPutint;};class BBB:public sigslot::has_slots<>{public:void bputstr(string str);void bputint(int a,int b);};void BBB::bputstr(string str){cout<<str<<endl;}void BBB::bputint(int a,int b){cout<<"a="<<a<<",b="<<b<<endl;}int _tmain(int argc, _TCHAR* argv[]){AAA a;BBB b;a.Onput.connect(&b,&BBB::bputstr);a.OnPutint.connect(&b,&BBB::bputint);a.Onput("this is a test!");a.OnPutint(1,9);getchar();return 0;}
也可用于类和成员变量之间的相互调用
#include "stdafx.h"#include "sigslot.h"class AAA{public:sigslot::signal1<string> Onput;sigslot::signal2<int, int> OnPutint;};class BBB:public sigslot::has_slots<>{public:BBB();~BBB();AAA a;void bputstr(string str);void bputint(int a,int b);};BBB::BBB(){ a.Onput.connect(this,&BBB::bputstr); a.OnPutint.connect(this,&BBB::bputint);}BBB::~BBB(){}void BBB::bputstr(string str){cout<<str<<endl;}void BBB::bputint(int a,int b){cout<<"a="<<a<<",b="<<b<<endl;}int _tmain(int argc, _TCHAR* argv[]){BBB b;b.a.Onput("this is a test!");b.a.OnPutint(1,9);getchar();return 0;}
用于MFC中,控件变量消息传递,如对话框上有个按钮,按钮按下松开的消息需要发送给对话框,由对话框处理,使用sigslot就不用发送消息实现了。
class CBtnTest : public CButton{DECLARE_DYNAMIC(CBtnTest)public:CBtnTest(CWnd* pParent = NULL); // standard constructorvirtual ~CBtnTest();sigslot::signal0<> Onbtndown;sigslot::signal0<> Onbtnup;// Dialog Dataenum { IDD = IDD_MFCTEST_DIALOG };protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV supportDECLARE_MESSAGE_MAP()public:afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnLButtonUp(UINT nFlags, CPoint point);};
<pre name="code" class="cpp">void CBtnTest::OnLButtonDown(UINT nFlags, CPoint point){// TODO: Add your message handler code here and/or call defaultOnbtndown();CButton::OnLButtonDown(nFlags, point);}void CBtnTest::OnLButtonUp(UINT nFlags, CPoint point){// TODO: Add your message handler code here and/or call defaultOnbtnup();CButton::OnLButtonUp(nFlags, point);}
#include "BtnTest.h"// CmfctestDlg dialogclass CmfctestDlg : public CDialog,public sigslot::has_slots<>{// Constructionpublic:CmfctestDlg(CWnd* pParent = NULL);// standard constructorCImage m_img;CImage m_img2;// Dialog Dataenum { IDD = IDD_MFCTEST_DIALOG };protected:virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support// Implementationprotected:HICON m_hIcon;// Generated message map functionsvirtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()public:afx_msg void OnBnClickedBtnOpenimg();void CreateStretchImage(CImage* pImage,CImage* DstImage,int height,int width);afx_msg void OnBnClickedBtnSlot();void OnBtnDown();void OnBtnUp();CBtnTest m_btnslot;
}
CmfctestDlg::CmfctestDlg(CWnd* pParent /*=NULL*/): CDialog(CmfctestDlg::IDD, pParent){m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);m_btnslot.Onbtndown.connect(this,&CmfctestDlg::OnBtnDown);m_btnslot.Onbtnup.connect(this,&CmfctestDlg::OnBtnUp);}
0 0
- sigslot.h的使用
- sigslot.h个人的想法
- sigslot库的使用
- libjingle sigslot的使用
- sigslot库的使用2
- sigslot库的简单使用
- webrtc中的sigslot的使用
- sigslot库的简单使用
- 信号槽库:sigslot.h和sigc++使用
- [C++]sigslot.h
- [sigslot] WebRTC sigslog.h
- vs2003 使用 sigslot
- 有用的库-sigslot
- Sigslot
- sigslot
- sigslot的动态模板版本
- C++中的“信号和槽”机制,sigslot.h
- webrtc sigslot 使用以及源码分析
- kafka基本介绍
- 数据结构与算法 题集
- 33. PHP Sessions
- 如何使用ASIHTTPRequest来进行网络请求的
- BZOJ 题目1798: [Ahoi2009]Seq 维护序列seq(双标记线段树)
- sigslot.h的使用
- jQuery Mobile入门
- Android小知识点、小疑问之 ListView中的灵异事件ListView跟Button 不能同时点击
- JVM的GC(概念与深入)
- Ubuntu14.04 LTS更新源
- 列表生成式
- Android x86模拟器Intel Atom x86 System Image配置与使用方法
- STL学习笔记之traits技术
- python正则表达式例子