QT的核心-----signals & slots
来源:互联网 发布:为什么域名要有别名 编辑:程序博客网 时间:2024/05/22 17:23
signals和slots机制是QT的根本。
slots和c++的成员函数(member function)几乎一样的,它们能定义为virtual,能overloaded,能定义为public,protected或private。能和c++其他成员函数一样
被直接调用,参量(paramters)能定义为任何类型,他与其它成员函数不同的是它能连接signal,当signal发射(emitted)时,它能自动调用。
它们格式一般为:
connect(sender,SIGNAL(signal),receiver,SLOT(slot));
sender和receiver必需为指向一个QObject对象的指针。而signal和slot只需指出参量类型而不用写出产量名称。
以下是一些可能发生的例子。
a:一个signal能连接多个slots。
例如: connect(slider,SIGNAL(valueChange(int)),spinBox,SLOT(setValue(int)));
connect(slider,SIGNAL(valueChange(int)),this,SLOT(updateValue(int)));
b:多个signal能连接一个slots。
connect(lcd, SIGNAL(overflow()),
this, SLOT(handleMathError()));
connect(calculator, SIGNAL(divisionByZero()),
this, SLOT(handleMathError()));
c:一个signal能连接其他signal。
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SIGNAL(updateRecord(const QString &)));
d:连接能够删除。
disconnect(lcd, SIGNAL(overflow()),
this, SLOT(handleMathError()));
要成功连接signal到slot,必须要参量类型及数量相同。
connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(processReply(int, const QString &)));
但万事无绝对,如果signal比slot参量多,多出参量可以忽略。
例如:connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(checkErrorCode(int)));
slots和c++的成员函数(member function)几乎一样的,它们能定义为virtual,能overloaded,能定义为public,protected或private。能和c++其他成员函数一样
被直接调用,参量(paramters)能定义为任何类型,他与其它成员函数不同的是它能连接signal,当signal发射(emitted)时,它能自动调用。
它们格式一般为:
connect(sender,SIGNAL(signal),receiver,SLOT(slot));
sender和receiver必需为指向一个QObject对象的指针。而signal和slot只需指出参量类型而不用写出产量名称。
以下是一些可能发生的例子。
a:一个signal能连接多个slots。
例如: connect(slider,SIGNAL(valueChange(int)),spinBox,SLOT(setValue(int)));
connect(slider,SIGNAL(valueChange(int)),this,SLOT(updateValue(int)));
b:多个signal能连接一个slots。
connect(lcd, SIGNAL(overflow()),
this, SLOT(handleMathError()));
connect(calculator, SIGNAL(divisionByZero()),
this, SLOT(handleMathError()));
c:一个signal能连接其他signal。
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SIGNAL(updateRecord(const QString &)));
d:连接能够删除。
disconnect(lcd, SIGNAL(overflow()),
this, SLOT(handleMathError()));
要成功连接signal到slot,必须要参量类型及数量相同。
connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(processReply(int, const QString &)));
但万事无绝对,如果signal比slot参量多,多出参量可以忽略。
例如:connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),
this, SLOT(checkErrorCode(int)));
- QT的核心-----signals & slots
- QT的核心-----signals & slots .
- QT的核心-----signals & slots
- Qt学习笔记1--更高级Signals and Slots的用法
- qt 的 signals宏和slots宏
- QT signals and slots
- QT Signals and Slots
- Qt Signals and Slots
- QT signals and slots
- QT Signals & Slots
- QT signals and slots
- QT signals and slots
- QT signals and slots
- QT signals and slots
- Qt文档----Signals and Slots
- Qt文档----Signals and Slots
- 2)Qt~Signals and Slots~
- QT的信号和槽机制:Signals and Slots
- OFN鼠标驱动(三) -- I2C驱动的移植(2)
- Eclipse必备常识
- ActionScript3.0中往Array数组中插入值
- [Internet]12个国外免费DNS服务
- 在main函数之前调用函数,以及对设计的作用
- QT的核心-----signals & slots
- Android ApiDemos示例解析(56):Graphics->BitmapPixels
- (学习记)Adroid 模拟器输入中文!
- define(宏)中#和##的用法
- 关于C++ Qt
- 浪潮实习8.16
- 在 AIX 上实现 Java: 下载、安装和配置
- (连载)一步一步教你做黑白棋游戏(一)
- sql创建临时表或视图增加 自增列