Lambda function as slot
Added by Freddy Martinez Garcia over 9 years ago
Hi guys...
why compiler give error with this code ?
WPushButton* cancelButton = new WPushButton("Cancel");
cancelButton->clicked().connect([=](){
// limpiando los edit y poniendo el focus en el login
this->m_loginEdit->setText(u8"");
this->m_passwordEdit->setText(u8"");
this->m_loginEdit->setFocus(true);
});
the error is:
../TestStore/LoginForm.cpp:19:47: note: candidate is:
../TestStore/LoginForm.cpp:19:49: note: LoginForm::init()::<lambda()>
../TestStore/LoginForm.cpp:19:49: note: candidate expects 0 arguments, 1 provided
can I use lambda c++11 as slot just like Qt ??? I'm a Qt developer, not Wt developer...
regards
Replies (3)
RE: Lambda function as slot - Added by Trigve Siver over 9 years ago
I think that lambda should have 1 parameter. You have none.
RE: Lambda function as slot - Added by Steven Descheemaeker over 9 years ago
you need std::bind like :
cancelButton->clicked().connect(std::bind([=](){
// limpiando los edit y poniendo el focus en el login
this~~m_loginEdit>setText(u8"");m_passwordEdit~~>setText(u8"");
this
this~~m_loginEdit~~>setFocus(true);
}));
RE: Lambda function as slot - Added by Wim Dumon over 9 years ago
The std::bind() is indeed a convenient method to 'throw away' parameters that you don't care about.
Wim.