Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ gcc:使用lambda函数编译Qt代码_C++_Qt_Lambda_Compiler Errors - Fatal编程技术网

C++ gcc:使用lambda函数编译Qt代码

C++ gcc:使用lambda函数编译Qt代码,c++,qt,lambda,compiler-errors,C++,Qt,Lambda,Compiler Errors,我得到了一段带有lambda函数的代码: QMenu menu(this); menu.addAction("Set file", this, [this, i](){this->setFile(i);}); 其中,setFile(int i)是在mymain窗口类中定义的无效方法 它在使用MSVC2015编译时工作,但在gcc 4:4.9.2-2中不工作,这会导致以下错误: 错误:对“QMenu::addAction(const char)”的调用没有匹配的函数 [6] ,MyMain

我得到了一段带有lambda函数的代码:

QMenu menu(this);
menu.addAction("Set file", this, [this, i](){this->setFile(i);});
其中,
setFile(int i)
是在
mymain窗口
类中定义的无效方法

它在使用MSVC2015编译时工作,但在gcc 4:4.9.2-2中不工作,这会导致以下错误:

错误:对“QMenu::addAction(const char)”的调用没有匹配的函数 [6] ,MyMainWindow*,MyMainWindow::eventFilter(QObject*, QEvent*)::)' addAction(“setFile”,this,this,i{this->setFile(i);})

我的qmake文件包含:

CONFIG += c++11
我还尝试添加:

QMAKE_CXXFLAGS += -std=c++11

但这并没有解决问题。如何编译此代码?

。不能将捕获lambda强制转换为函数pointer@Rakete1111
QMenu::addAction
不接受函数指针。@n.m.确保您使用的是相同的Qt版本。@raket1111它是一个模板(文档有误导性)。。不能将捕获lambda强制转换为函数pointer@Rakete1111
QMenu::addAction
不接受函数指针。@n.m.请确保您使用的是相同的Qt版本。@Rakete1111它是一个模板(文档有误导性)。