1开发环境
- Qt Creator, Qt5.5
2 遇到的问题
今天在学习QT时,遇到一个error,在学习信号和槽函数时,在connect函数中,直接传入lambda表达式时,会报这样的错误
- 代码示例
// 利用lambda表达式,实现点击按钮,关闭窗口
QPushButton* btn2 = new QPushButton;
btn2->setText("关闭");
btn2->move(100, 0);
btn2->setParent(this);
connect(btn2, &QPushButton::clicked, this, [=](){
this->close();
});
- 错误提示
C:\qt_project\project02\widget.cpp:90: error: no matching function for call to 'Widget::connect(QPushButton*&, void (QAbstractButton::*)(bool), Widget*, Widget::Widget(QWidget*)::<lambda()>)'
});
^
3 解决方法
在.pro文件中加上
CONFIG += c++11
可以解决这个error。