Qt5信号槽的新语法与lambda函数

New Connection Syntax

In addition to the still available well known way to connect signals and slots, new overloads of QObject::connect have been added allowing you to connect signals and slot using pointer to member functions:

QObject::connect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue);

The new syntax provides compile time checking of the compatibility between signals and slots, automatic conversion of the arguments if there is an implicit cast between the types, and solve many problems occurring because of typedef or namespaces.

Additionally, if your compiler supports C++11 lambdas, you can even connect directly to a lambda function.

connect(sender, &QObject::destroyed, [=](){ this->m_objects.remove(sender); });


参考:

信号与槽的新语法(Qt5)

New Signal Slot Syntax in Qt 5

Using C++11 Lambdas As Qt Slots

Differences between String-Based and Functor-Based Connections

转载于:https://www.cnblogs.com/21207-iHome/articles/7418581.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值