-1

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?

rgettman
  • 176,041
  • 30
  • 275
  • 357

1 Answers1

2

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

THE_CHOODICK
  • 125
  • 6