[Qt-interest] block signals only in current class
Volker Poplawski
volker at openbios.org
Tue Aug 11 11:01:55 CEST 2009
On Tuesday 11 August 2009 10:33:11 Matthias Pospiech wrote:
> I have a class (RotationStage) that has a variable 'velocity'. The class
> is a Singleton.
>
> This velocity can be changed in different classes and is displayed in
> different dialogs.
> If the velocity is changed with
> RotationStage->setVelocity(velocity)
> then RotationStage emits 'velocity changed', so that all dialogs can
> update their velocity displays.
>
> However, I want to avoid that the signal of RotationStage changes the
> QDoubleSpinBox, that originaly
> changed the velocity value. But if I would block the Signals from
> RotationStage "RotationStage->blockSignals(true);",
> that would stop every dialog from getting this signal which is not what
> I want.
>
> Or do this signals apply only to my class despite that RotationStage is
> a Singleton?
The usual approach to avoid such "update-loops" is to check if the updated
value actually differs from the current value.
This can be done at in your model (speaking in model-view terms) and/or in the
views.
for example:
void A::setVelocity(int newValue)
{
if (m_currentValue != newValue)
{
m_currentValue = newValue;
emit velocityChanged(m_currentValue);
}
else
{
// do nothing
}
}
Greetings
....Volker
More information about the Qt-interest-old
mailing list