title: QListView with a QStandardItemModel and checkbox-enabled QStandardItems: How to capture *only* check-state changes?
body: <p>I have the following (simplified) code to add <code>QStandardItem</code>'s to a <code>QStandardItemModel</code>, attach the model to a <code>QListView</code>, and connect signals of my choice from the model to a function of my choice:</p>
  
  <pre><code>// MyUIContainer derives from QWidget
  MyUIContainer::SetItems()
  {
      // Inside a member function where model/items are added to a QListView...
  
      // This code does not show deletion of existing ItemSelectionModel
  
      QStandardItemModel * model = new QStandardItemModel(ui-&gt;listView);
  
      // In the real code, data is set in each QStandardItem
      model-&gt;setItem( 0, new QStandardItem() );
      model-&gt;setItem( 1, new QStandardItem() );
      model-&gt;setItem( 2, new QStandardItem() );
  
      connect(model,
              SIGNAL(itemChanged(QStandardItem*)),
              this,
              SLOT(ReceiveChange(QStandardItem*)));
  
      // I have also tried connecting to this signal - same problem described below
      //connect(model, SIGNAL(dataChanged(const QModelIndex &amp;, const QModelIndex &amp;, const QVector&lt;int&gt;)), this, SLOT(ReceiveChange(const QModelIndex &amp;, const QModelIndex &amp;, const QVector&lt;int&gt;)));
  
      ui-&gt;listView-&gt;setModel(model);
  }
  
  MyUIContainer::ReceiveChange(QStandardItem * item)
  {
      // Problem!  This slot is called *three times*
      // whenever the check state of an item changes
  }
  </code></pre>
  
  <p>As the code comment indicates, there is a problem: The <code>itemChanged()</code> \ <code>ReceiveChange()</code> signal \ slot combination is called <strong>three</strong> times whenever the check state of a checkbox in the <code>QListView</code> changes <strong>once</strong>.</p>
  
  <p>I understand that I can create my own Model class that is derived from <code>QAbstractItemModel</code>, and (if I understand correctly) handle mouse clicks in the view myself, emitting signals such as, for example, the <code>itemChanged</code> signal with a proper user-defined role so that a change in checkbox state can be handled only once.</p>
  
  <p>However, the latter approach requires me to be careful to handle all possible scenarios of mouse clicks &amp; keyboard events that could result in a changed checkbox state.  I was hoping, and assuming, that this logic has been handled inside the Qt library itself, so that I don't have to - so that I can simply receive a signal (or some other message) when the check state of a checkbox changes.</p>
  
  <p>Note that it seems that <code>QListWidget</code> (rather than <code>QListView</code>) also has exactly the same problem.</p>
  
  <p>So, my question is: Without writing my own Model class derived from <code>QAbstractItemModel</code> - with its requirement that I myself write code to handle every possible way that a check state can change - how do I capture a changed check state (via a signal or otherwise) such that I can unambiguously capture every time a check state changes <strong>once and only once</strong> per check state change?</p>
  
  <p><strong>ADDENDUM</strong></p>
  
  <p>With apologies - as I took great care in ruling everything else out - Riateche's comment made it clear to me that the behavior is not <em>supposed</em> to work in the way this question highlighted.  Finally, I have indeed tracked down the problem to the fact that I was calling <code>connect()</code> multiple times.</p>