3.信号槽
1.信号槽最常用的方式:
connect(sender, signal,
receiver, slot);
第一个对象是发出信号的对象,第二个是发送对象发出的信号,第三个是接收信号的对象,第四个是接收对象在接收到信号后需要调用的函数。
Qt5中QObject::connect()的五个重载:
QMetaObject::Connection connect(const QObject *, const char *,
const QObject *, const char *,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const QMetaMethod &,
const QObject *, const QMetaMethod &,
Qt::ConnectionType);
QMetaObject::Connection connect(const QObject *, const char *,
const char *,
Qt::ConnectionType) const;
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
const QObject *, PointerToMemberFunction,
Qt::ConnectionType)
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
Functor);
x
18
1
QMetaObject::Connection connect(const QObject *, const char *,
2
const QObject *, const char *,
3
Qt::ConnectionType);
4
5
QMetaObject::Connection connect(const QObject *, const QMetaMethod &,
6
const QObject *, const QMetaMethod &,
7
Qt::ConnectionType);
8
9
QMetaObject::Connection connect(const QObject *, const char *,
10
const char *,
11
Qt::ConnectionType) const;
12
13
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
14
const QObject *, PointerToMemberFunction,
15
Qt::ConnectionType)
16
17
QMetaObject::Connection connect(const QObject *, PointerToMemberFunction,
18
Functor);
2.信号槽要求信号和槽的参数一致,所谓一致,是参数类型一致。如果不一致,允许的情况是槽函数的参数可以比信号参数少。即使如此,槽函数存在的那些参数的顺序也必须和信号的前面几个一致起来。
3.Qt5中,可以将一个对象的信号连接到Lambda表达式。