3.信号槽
Posted lyndonmario
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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表达式。
以上是关于3.信号槽的主要内容,如果未能解决你的问题,请参考以下文章