Reputation: 13575
Code is here
void A::fun()
{
QAction* act = new QAction(this);
QAction* act2 = new QAction(this);
connect(act, QAction::triggered, [this, &act2]() {...; act2.setDisable(true);}
// crash when &act2 is used to capture the variable
// but it is okay using act2 to capture the variable
}
What is the reason? Thanks.
Upvotes: 0
Views: 554
Reputation: 22366
You are taking a reference of act2
even though it is a pointer that will go out scope, that is why copying the pointer works.
Upvotes: 3