深入信号和槽(Signals and Slots in Depth)
2010-01-27 19:50
295 查看
1、一个信号可以连接到多个槽:connect(slider, SIGNAL(valueChanged(int)),spinBox, SLOT(setValue(int)));connect(slider, SIGNAL(valueChanged(int)),this,SLOT(updateStatusBarIndicator(int)));当信号发出后,槽函数都会被调用,但是调用的顺序是随机的,不确定的。2、多个信号可以连接到一个槽connect(lcd, SIGNAL(overflow()), this, SLOT(handleMathError()));connect(calculator, SIGNAL(divisionByZero()),this, SLOT(handleMathError()));任何一个信号发出,槽函数都会执行。3、一个信号可以和另一个信号相连connect(lineEdit, SIGNAL(textChanged(const QString &)),this, SIGNAL(updateRecord(const QString &)));第一个信号发出后,第二个信号也同时发送。除此之外,信号与信号连接上和信号和槽连接相同。4、连接可以被删除disconnect(lcd, SIGNAL(overflow()),this, SLOT(handleMathError()));这个函数很少使用,一个对象删除后,Qt 自动删除这个对象的所有连接。信号和槽函数必须有着相同的参数类型,这样信号和槽函数才能成功连接:connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),this,SLOT(processReply(int, const QString &)));如果信号里的参数个数多于槽函数的参数,多余的参数被忽略:connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),this,SLOT(checkErrorCode(int)));如果参速类型不匹配,或者信号和槽不存在,在debug 状态时,Qt 会在运行期间给出警告。如果信号和槽连接时包含了参数的名字,Qt 将会给出警告。
相关文章推荐
- 深入信号和槽(Signals and Slots in Depth)
- 深入信号和槽(Signals and Slots in Depth)
- 深入信号和槽(Signals and Slots in Depth)
- 深入信号和槽(Signals and Slots in Depth)
- 2.2深入信号和槽(Signals and Slots in Depth)
- 2.2深入信号和槽(Signals and Slots in Depth)
- Signals and Slots in Depth
- 【C2】对话框【S2】Signals and Slots in Depth
- Qt:信号与槽(Signals and Slots) 上
- QT的信号和槽机制:Signals and Slots
- 解析Qt的信号-槽机制是如何工作的 - How Qt Signals and Slots Work
- Qt:信号与槽(Signals and Slots) 上
- Qt signals and slots in different classes
- Qt:信号与槽(Signals and Slots) 下
- Qt:信号与槽(Signals and Slots) 下
- How Qt Signals and Slots Work - Qt的信号-槽机制是如何工作的
- 解析Qt的信号-槽机制是如何工作的 - How Qt Signals and Slots Work
- 信号(signals)和槽(slots) 精…
- QT signals and slots
- Dynamic Signals and Slots