PDA

View Full Version : Question about tutorial no. 6



jacopo
26th August 2009, 14:46
Hi all,
I'm running tutorial number 6: http://doc.trolltech.com/4.4/tutorials-tutorial-t6.html
Inside the LCDRange constructor there is the following:

slider->setValue(0);
connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));
however, I think it doesn't work as expected...at least, on startup: lcd displays the correct number when the slider moves, but it doesn't happen when slider->setValue(0), or generally, slider->setValue(some int) is executed.
For example

slider->setValue(45);
connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));
moves the slider to right position, but lcd displays 0.
Instead, moving connect statement before slider->setValue()

connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));
slider->setValue(0);
does the trick, so lcd displays 45 correctly.

Can I have some explanation of this ?

spirit
26th August 2009, 15:21
setValue emits a signal valueChanged, but in this case


slider->setValue(45);
connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));

the signal is not handled, because there is no connection yet insted of this case


connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));
slider->setValue(45);

jacopo
26th August 2009, 16:10
Yeah...so easy to understand. :rolleyes:
Thanks !!

victor.fernandez
27th August 2009, 08:05
slider->setValue(45);
connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT( display(int)));

In fact, this is a possible way to set default values without triggering the slots those signals are connected to.