Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect QMenu::addAction directly to lambda (function signature mismatch)

Tags:

c++

qt

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.

like image 284
user2366975 Avatar asked Nov 18 '16 19:11

user2366975


1 Answers

The addAction overload you're looking for has been added in Qt 5.6.

like image 196
Kuba hasn't forgotten Monica Avatar answered Sep 28 '22 04:09

Kuba hasn't forgotten Monica