That's just exactly the example from the Signals & Slots documentation:
Counter a, b; QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int))); a.setValue(12); // a.value() == 12, b.value() == 12 b.setValue(48); // a.value() == 12, b.value() == 48
Note that the
setValue()
function sets the value and emits the signal only ifvalue != m_value
. This prevents infinite looping in the case of cyclic connections (e.g., ifb.valueChanged()
were connected toa.setValue()
).
So in this case it's a safety feature of setValue
. This is also documented in the setValue
function:
setValue()
will emitvalueChanged()
if the new value is different from the old one.
If you change the value in your slider, it will emit, which will change the value in your spin, which will emit, which now doesn't change the value in your slider.