With Qt 5 and the C ++ 11 compiler, the idiomatic way to do such things is to give the functor a connect :
connect(action1, &QAction::triggered, this, [this]{ onStepIncreased(1); }); connect(action5, &QAction::triggered, this, [this]{ onStepIncreased(5); }); connect(action10, &QAction::triggered, this, [this]{ onStepIncreased(10); }); connect(action25, &QAction::triggered, this, [this]{ onStepIncreased(25); }); connect(action50, &QAction::triggered, this, [this]{ onStepIncreased(50); });
The third argument to connect nominally optional. It is used to set the context of the stream in which the functor will be executed. This is always necessary when a functor uses an instance of QObject . If a functor uses multiple instances of QObject , they must have some common parent that controls their lifetime, and the functor must reference this parent or must ensure that objects overflow the functor.
On Windows, this works on MSVC2012 and later.
Kuba Ober Mar 14 '14 at 16:57 2014-03-14 16:57
source share