信号与槽
来源:互联网 发布:超级记忆训练软件 编辑:程序博客网 时间:2024/05/21 11:31
继承自QObject的类中,除了c++的成员函数之外还有槽函数
槽函数可以通过代码手动调用,也可以通过信号调用
信号与槽的连接:
使用QObject的静态成员函数connect进行连接
bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection ) [static]
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns true if the connection succeeds; otherwise returns false.
信号与槽的参数个数,类型顺序必须匹配
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
SIGNAL() and SLOT() 中的函数参数只写参数类型就行(如果有参数的话),不应该加形式参数
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
自定义信号:
自定义信号时确保该类继承与QObject或其子类,在类声明中使用宏Q_OBJECT
定义信号时,只需写信号函数的声明,不需要定义,返回类型为void
class 类名:public QObject或其子类{
Q_OBJECT
//其他成员
signals:
void 信号名(参数);
};
发送信号:emit 信号函数
槽函数的定义和声明:
槽 函数不仅需要声明,而且需要定义(因为要有操作的实现)
class 类名:public QObject或其子类{
Q_OBJECT
//其他成员
public slots: //public 或private 或protect
void 槽名(参数);
};
- Qt 信号与信号,信号与槽
- 信号与槽进阶
- qt 槽与信号
- 关于信号与槽
- QT信号与槽
- QT 信号与槽
- 信号与槽
- QT信号与槽
- Qt信号与槽
- Qt信号与槽
- QT信号与槽
- 信号与槽
- 信号与槽..
- Qt信号与槽
- QT信号与槽
- 信号与槽
- QT信号与槽
- 信号与槽
- 多线程用到类函数中
- 考研vs保研? 看华中师大学子谈保研、考研如何抉择?
- Quartus II 15.0仿真入门
- 洛谷 P1345 [USACO5.4]奶牛的电信Telecowmunication
- 关于生物医学工程{血站+软件}的看法
- 信号与槽
- LINUX下面NetworkManager和network冲突的问题
- Java swing实现Visio中对直线、曲线、折线的画及拖动删除
- C++入门基础知识
- 基于iOS的网络音视频实时传输系统(四)- 自定义socket协议(TCP、UDP)
- 51nod 1005 大数加法
- 【简记】Operating System——process synchronization in Java
- 常见OJ评判结果对照表,作为ACMer你懂得!
- MXNet的源码编译过程总结