Let's say I have Widget containing a Button
and a Spinbox
. When the Button is clicked I wish to emit the value of the Spinbox.
I see two possible ways to do this:
Either I can create a private member function
//...
connect(m_Button, &QPushButton::clicked, this, &SomeWidget::emitSpinboxValue);
//...
SomeWidget::emitSpinboxValue() {
emit spinboxValueChanged(m_Spinbox->value());
}
Or I can directly do that in a lambda:
//...
connect(m_Button, &QPushButton::clicked, [this]() { emit spinboxValueChanged(m_Spinbox->value()) });
//...
The lambda way looks neater (since I do not need to create a rather empty member function), but on the other hand seeing that emit
in the lambda gives me a bad feeling in my gut.
So, is emitting signals in a lambda ok (and my gut oversensitive), or is it bad style (or do I even set myself up for some unexpected trouble in the future)