Pass multiples arguments to a slot Qt

208 Views Asked by At

I'm using a Qt horizontal slider and I want to connect its valueChanged signal to a slot I defined. However I need to access a specific member inside this slot to modify a variable thanks to the int I set with the slider. Until now, my connect line has looked like this:

connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setVariable(int)));

Is it possible to pass more than one argument to my slot? What I'd like to do is something like:

connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setVariable(int, pointerToMember*)));

If not how can I proceed?

1

There are 1 best solutions below

0
On

Yes, you can, but you need to use new connect style, so you can pass lambda function

connect(slider, &QAbstractSlider::valueChanged, this, [=](int &new_value) { this->setVariable(new_value, ... );});

Edit: This works only in Qt5 and above