axylp123的个人主页

http://www.qtcn.org/bbs/u/154703  [收藏] [复制]

axylp123

  • 1

    关注

  • 1

    粉丝

  • 16

    访客

  • 等级:新手上路
  • 总积分:15
  • 男,1987-10-10

最后登录:2017-06-01

更多资料

日志

2.2 深入介绍信号和槽

2015-11-27 09:54
bool QObject::connect(const QObject   *sender,     //发出信号的对象
                                         const char          *signal,     //信号
                                         const QObject   *receiver,   //接收信号的对象
                                         const char          *method,     //对象接收到信号后的处理
                                         Qt::ConnectionType type = Qt::AutoConnection ) [static] //连接方式
                                           type:
                                               Qt::AutoConnection
                                               Qt::DirectConnection
                                               Qt::QueuedConnection
                                               Qt::BlockingQueuedConnection
                                               Qt::UniqueConnection
                                               Qt::AutoCompatConnection
一个信号连接多个槽
connect(pSlider, SIGNAL(valueChanged(int)), pSpinBox, SLOT(setValue(int)));
connect(pSlider, SIGNAL(valueChanged(int)), pLabel, SLOT(setNum(int)));
当发射valueChanged(int)信号时,以不确定的顺序逐一调用槽函数。
多个信号连接一个槽
connect(pSlider, SIGNAL(valueChanged(int)), pLabel, SLOT(setNum(int)));
connect(pSpinBox, SIGNAL(valueChanged(int)), pLabel, SLOT(SetNum(int)));
无论发射哪个信号,都将执行pLabel的setNum(int)槽函数
一个信号连接另一个信号
connect(pBtn, SIGNAL(clicked()), this, SIGNAL(textChange()));
当发射clicked()信号时,textChange()信号被发射
移除连接
disconnect(pSlider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
较为少用,因为当对象被删除时,槽连接也被删除
如果参数类型不匹配,或信号/槽不存在时,应用程序使用调试模式构建后,Qt会在运行时发出警告。
与之类似,connect()进行关联时,如果信号和槽的名字中包含了参数名,Qt也会发出警告。
connct()连接时需要注意:
1.信号和槽的参数列表完全相同。
2.信号函数的参数个数大于槽函数参数个数,且参数列表从左向右类型匹配,信号函数中多余的参数被忽略。
3.参数的const属性要匹配
分类:C++GUIQt4|回复:1|浏览:782|全站可见|转载
 
 
删除

z609932088:学习了,这回不会弄混 了

2015-11-28 21:48 -

Powered by phpwind v8.7 Certificate Copyright Time now is:04-28 00:06
©2005-2016 QTCN开发网 版权所有 Gzip disabled