在使用信号槽的时候可以使用自定义的匿名函数来代替需要输出的槽函数:
定义一个匿名函数:
[=](){
// dosomething
};
如果需要传入参数:
[=](int x ,int y)mutable{
qDebug() << x= << x << y= << y;
}(100,40);
其中需要加入 mutable 关键字。其中传入的参数是 x = 100, 和 y = 40
在槽函数中调用这个函数表达式:
connect(bt2,&QPushButton::clicked,[=]() {
MainWindow::close(); // 主页面关闭
});