qt creator 信号 槽 lambda 表达式
https://www.bilibili.com/video/BV1XW411x7NU?p=14
QPushButton *b4 = new QPushButton(this);
b4->setText("Lambda表达式");
b4->move(150,150);
int a=10, b=100 ;
测试1:
// connect(b4,&QPushButton::released,
// [b4 ,a,b]()
// {
// b4->setText("123");
// qDebug() << "1111" <<a<<b;
// }
// );
// connect(b4,&QPushButton::released,
// [=]() mutable
// {
// b4->setText("123");
// qDebug() << "1111" <<a<<b;
// a = 11 ;
// }
// );
connect(b4,&QPushButton::clicked,
[=](bool isCheck) mutable
{
b4->setText("123");
qDebug() << "1111" <<a<<b;
a = 11 ;
qDebug() <<isCheck ;
}
);
本文通过一个QtCreator中的示例介绍了如何使用Lambda表达式连接信号与槽。示例中创建了一个QPushButton,并在其点击事件中使用Lambda表达式来改变按钮文本及调试输出。
9121

被折叠的 条评论
为什么被折叠?



