How can I connect a QAction
directly with lambda slot?
QMenu m;
Working:
QAction newSubfolder(QIcon(":/icons/newfolder.png"),tr("New Subfolder"),&m);
m.addAction(&newSubfolder);
connect(&newSubfolder,&QAction::triggered,
this,[this,p](){qDebug()<<"New Subfolder";});
Not working:
m.addAction(QIcon(":/icons/newfolder.png"),tr("New Subfolder"),
[this,p](){qDebug()<<"New Subfolder";});
Error:
No matching function for call to 'QMenu::addAction(QIcon, QString, FolderMenuWidget::showContextMenu(QPoint)::__lambda0)'
[this,p](){qDebug()<<"New Subfolder";});
^
Yes I see the error message but I don't understand what I need to change for the lambda slot. It also does not work if I add the member pointer this
before the lambda.
This is in Qt 5.3.
The addAction
overload you're looking for has been added in Qt 5.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With