日志
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属性要匹配 |
下一篇: 2.3 快速设计对话框
上一篇: 2.1 子类化QDialog
-
删除
z609932088:学习了,这回不会弄混 了
2015-11-28 21:48 -