PDA

View Full Version : signals and control arrays



zorro68
31st August 2007, 14:29
I have programm an array with four Sliders (SLDpaso[i]). I connect each slider with the function setIsoValueInt like this:


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

Wizard
31st August 2007, 14:32
Use QObject::sender() to identify source of signal.

marcel
31st August 2007, 14:48
Or you can use a QSignalMapper, it is safer than sender(). There is an example in the docs.

zorro68
31st August 2007, 14:48
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.

marcel
31st August 2007, 15:00
Whatever....

Wizard
31st August 2007, 15:00
You can find sender() in SLDpaso array, or use QSignalMapper. If you have a lot of sliders (more than 50) QSignalMapper may be faster

zorro68
31st August 2007, 19:11
I have read obout sender() function and I need more help. I have programm this:



for (int i=0;i<max_contorno;i++){
connect(SLDpaso[i], SIGNAL(valueChanged(int)), this, SLOT(setIsoValueInt(int)));
}


and in setIsoValueInt:



QSlider *SLDp = (QSlider *)sender();


But i dont know how to obtain the index of the Sliders array

marcel
31st August 2007, 19:22
There:


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

zorro68
31st August 2007, 19:32
Marcel, this works fine. Thanks very very much.