Solved Adding Lambda Expression as Slot
-
I want to create a Combobox and add to every combo box I add a function.
connect(comboBox, SIGNAL(activated(QString)) ,this, [](QString text){ cout << text.toUtf8().constData() << endl; });
But I always get as result : No matching member function for call to 'connect'
-
@Domididongo Remove this:
connect(comboBox, SIGNAL(activated(QString)) ,[](QString text){ cout << text.toUtf8().constData() << endl; });
-
@Domididongo said in Adding Lambda Expression as Slot:
But I always get as result : No matching member function for call to 'connect'
connect(comboBox, QOverload<QString>::of(&QComboBox::activated) , this, [](const QString & text) { cout << text.toUtf8().constData() << endl; });
-
the new syntax needs the address of a class member:
connect(comboBox, &QComboBox::activated ,this, [](QString text){ cout << text.toUtf8().constData() << endl; });
-
Hi,
Because you are trying to use an overload that doesn't exists:
connect(comboBox, qOverload<QString>(&QComboBox::activated), this, [](const QString &text){ cout << text.toUtf8().constData() << endl; });
qOverload requires C++14.
You don't even need the
this
parameter.For more information, see here
-
@sneubert said in Adding Lambda Expression as Slot:
the new syntax needs the address of a class member:
connect(comboBox, &QComboBox::activated ,this, [](QString text){
cout << text.toUtf8().constData() << endl;
});won't compile, since there are more than one activated() methods with different signatures. Thus the compiler won't know which one to link to.
@SGaist said in Adding Lambda Expression as Slot:
qOverload requires C++14.
Just a note:
the functionqOverload<>()
requires C++14
the helper classQOverload<>::of()
also works since C++11 -
I'll be that guy. I apologise in advance.
This is literally spelled out for you in the docs. you just need to copy-paste that code into your code. I can't think of a better way the docs could make this clear
-
sorry I did not thought there´s an overload