lambda capture syntax
-
Hi to all,
i have to capture array index and pass it to a slot..
i've read some post about lambda but i can't do it..//arraySco[i] is a QCheckBox //connect(arraySco[i], SIGNAL(stateChanged()), this, CambiaMag(i)); //this is the goal connect(arraySco[i], SIGNAL(stateChanged()), this, [=] () {qDebug() << i;});
generate several errors..
i want capture "i" var and pass it to a SLOT (CambiaMag())
anyone can help me please? -
Hi to all,
i have to capture array index and pass it to a slot..
i've read some post about lambda but i can't do it..//arraySco[i] is a QCheckBox //connect(arraySco[i], SIGNAL(stateChanged()), this, CambiaMag(i)); //this is the goal connect(arraySco[i], SIGNAL(stateChanged()), this, [=] () {qDebug() << i;});
generate several errors..
i want capture "i" var and pass it to a SLOT (CambiaMag())
anyone can help me please?@TheCipo76 said in lambda capture syntax:
connect(arraySco[i], SIGNAL(stateChanged()), this, [=] () {qDebug() << i;});
that won't work, you'll need to use the new function pointer based syntax.
I would correct it for you but I'm missing crucial information.
- pointer to the class instance that has the stateChanged signal
- Name of the class that has the stateChanged signal
-
Hi to all,
i have to capture array index and pass it to a slot..
i've read some post about lambda but i can't do it..//arraySco[i] is a QCheckBox //connect(arraySco[i], SIGNAL(stateChanged()), this, CambiaMag(i)); //this is the goal connect(arraySco[i], SIGNAL(stateChanged()), this, [=] () {qDebug() << i;});
generate several errors..
i want capture "i" var and pass it to a SLOT (CambiaMag())
anyone can help me please?@TheCipo76 Use new syntax connection: https://wiki.qt.io/New_Signal_Slot_Syntax
-
@TheCipo76 said in lambda capture syntax:
connect(arraySco[i], SIGNAL(stateChanged()), this, [=] () {qDebug() << i;});
that won't work, you'll need to use the new function pointer based syntax.
I would correct it for you but I'm missing crucial information.
- pointer to the class instance that has the stateChanged signal
- Name of the class that has the stateChanged signal
-
alight
connect(arraySco[i], &QCheckBox::stateChanged, this, [=] ()->void {qDebug() << i;});
in case you want to use the argument, because state changed has an int argument:
connect(arraySco[i], &QCheckBox::stateChanged, this, [=] (int state)->void {qDebug() << i << state;});
-
alight
connect(arraySco[i], &QCheckBox::stateChanged, this, [=] ()->void {qDebug() << i;});
in case you want to use the argument, because state changed has an int argument:
connect(arraySco[i], &QCheckBox::stateChanged, this, [=] (int state)->void {qDebug() << i << state;});
-
@TheCipo76
And just so you know. The capture[=]
means "capture all local variables, by value" ([&]
would be the same but all by reference). In this case you only needi
, so you could have written[i]
here, or[i, j, ..]
for individual ones. Just so you know if you want to use that or see it elsewhere in examples.