signals and control arrays
I have programm an array with four Sliders (SLDpaso[i]). I connect each slider with the function setIsoValueInt like this:
Code:
connect(SLDpaso[i], SIGNAL(valueChanged(int)), this, SLOT(setIsoValueInt(int)));
but in setIsoValueInt(int) function I want to know which slider I have used (which [i]). As you know, valueChanged(int) only emit the value of the slider, but not which slider has emitted the signal. How can I do that?
Thks.
PD:Sorry for my bad english
Re: signals and control arrays
Use QObject::sender() to identify source of signal.
Re: signals and control arrays
Or you can use a QSignalMapper, it is safer than sender(). There is an example in the docs.
Re: signals and control arrays
I'm reading help about QObject::sender(). But how to, because I want to know the index of the slider but not its name (QObject::sender()->objectName).
thanks for your quick answer.
Re: signals and control arrays
Re: signals and control arrays
You can find sender() in SLDpaso array, or use QSignalMapper. If you have a lot of sliders (more than 50) QSignalMapper may be faster
Re: signals and control arrays
I have read obout sender() function and I need more help. I have programm this:
Code:
for (int i=0;i<max_contorno;i++){
connect(SLDpaso[i], SIGNAL(valueChanged(int)), this, SLOT(setIsoValueInt(int)));
}
and in setIsoValueInt:
But i dont know how to obtain the index of the Sliders array
Re: signals and control arrays
There:
Code:
int sldIndex = -1;
for(int i = 0; i != max_contorno; ++i)
if(SLDpaso[i] == SLDp)
{
sldIndex = i;
break;
}
So, you should test sldIndex to be a valid value.
Regards
Re: signals and control arrays
Marcel, this works fine. Thanks very very much.