title: Qt 4.6 - C++ - QTreeWidgetItem Iterator
body: <p>I have a QTreeWidget with items in it. The first column contains a unique number. This is set via item->setData(0, 0, unique_number);. The second column contains a checkbox, set via item->setCheckState(1, Qt::Unchecked);. The user can select the items (s)he would like to work with and presses a button. The slot for this button will run a loop on the checked items. In the Qt documentation an example is given. You use the QTreeWidgetItemIterator. </p>
  
  <pre><code>QTreeWidgetItemIterator it(treeWidget);
   while (*it) {
       if ((*it)-&gt;text(0) == itemText)
           (*it)-&gt;setSelected(true);
       ++it;
   }
  </code></pre>
  
  <p>It also says that you can specify an argument in the constructor to only iterate over the checked items. The flag is : QTreeWidgetItemIterator::Checked. My slightly customized loop is as follows: </p>
  
  <pre><code>QTreeWidgetItemIterator it(treeWidget, QTreeWidgetItemIterator::Checked);
  
  while (*it)
  {
      QVariant w;
      w = (*it)-&gt;data(0, 0);
      std::cout &lt;&lt; "Selected item # " &lt;&lt; w.toInt() &lt;&lt; "\n";
      it++;
  
  }
  </code></pre>
  
  <p>This code will compile fine but won't work when you actually run the program. It doesn't print any values. </p>
  
  <p>Any tips? Thanks!</p>