title: Qt: How to update the GUI when the model changes?
body: <p>I use checkboxes in my GUI to toggle bits in a class controlling a maschine connected by signals/slots. </p>
  
  <p>I also need the opposite direction, because if some commands to the maschine toggle the same bits, my GUI should reflect the changes.</p>
  
  <p>My problem is: 
  When I click the checkbox, its state is not yet updated when the signal is sent. 
  So the first signal arrives at the maschine, the bit gets toggled, the maschine responds with the second signal and arrives at the GUI handler method 'updateCheckBoxXYZ'.
  Now I want to figure out if I need to update the checkbox. </p>
  
  <p>If the whole chain is started by user, the checkbox will be updated automatically at last.
  If an internal command directly toggled the bit, the checkbox will need to be checked to reflect the internal change.</p>
  
  <p>Because the checkbox has not been checked yet, I can not ask for 'isChecked()'.</p>
  
  <p>What should I do to not getting trapped in an endless loop?</p>
  
  <p><strong>Update:</strong> 
  I just tried something like the following code:</p>
  
  <pre><code>// slot called by toggled(bool)
  
  void DialogXY::checkBoxXYChanged(bool bState)
  {
      if (bState != m_bGuiStateXY)
      {
          m_bGuiStateXY = bState; 
          emit GuiXYChanged(bState);
          // optional: .. do some GUI related things ..
      }
  }
  
  
  // slot called on signal 'GuiXYChanged(bState)'
  
  void Machine::changeXY(int iModul, bool bState)
  {
      if (bState != m_bMachineStateXY)
      {
          emit MachineXYChanged(bState);
      }
      // .. change machine configuration ..
  }
  
  
  // slot called on signal 'MachineXYChanged(bState)'
  
  void DialogXY::updateCheckBoxXY(bool bState)
  {    
      if (bState != m_bStateXY)
      {
          ui.checkBoxXY-&gt;setChecked(bState);
          // will signal toggled()
      }
  }
  </code></pre>
  
  <p>But I need extra variables for each GUI item, 
  I have to initialize then correctly, etc.</p>
  
  <p>I would prefer something more elegant.</p>