title: Qt Signal Slot Architecture Unwanted Infinite Loop
body: <p>I've problem with qt signal-slot system.</p>
  
  <p>First I've created a class which is called System in Singleton pattern, so I can access it's instance where I want. System has a signal SelectionChanged.</p>
  
  <p>I've a list widget and I am connecting it's itemSelectionChanged signal to my custom slot which is called onSelectionChanged. In onSelectionChanged slot, I am emitting System's SelectionChanged signal. There is no problem yet.</p>
  
  <p>In my software design, a selection of object(s) can be used by many GUI widgets or custom classes and System's SelectionChanged signal can be emited by widgets other then the list widget.</p>
  
  <p>So I am creating a slot called OnSystemSelectionChanged in the list widget then connect it to the System's SelectionChanged signal. The OnSystemSelectionChangedSlot is like this.</p>
  
  <pre><code>void MyListWidget::OnSystemSelectionChanged(QObject *sender)
  {
      if (sender == this) return;
      // Then I want to get a list of selected objects and set them as selection of this widget like this:
      this-&gt;SetSelection(System::Instance()-&gt;GetSelectedObjects());
  }
  </code></pre>
  
  <p>But the problem is when I start to set the list widget's selected items, it is going to emit itemSelectionChanged signal and my onSelectionChanged slot will be called. Then the slot will emit System's SelectionChanged signal and then OnSystemSelectionChanged will be called too. It will stop through sender parameter but there is no method for setting list widget's selected items at once.</p>
  
  <p>How can I figure this problem out.</p>
  
  <p>I hope I did explain my problem well. Thanks in advance.</p>
  
  <p>Edit: Spelling and grammer errors are corrected.</p>