title: QTreeWidgetItem: How can I get the selected item?
body: <p>I am currently a student programmer using Qt to build a GUI inteface at work and I am currently running into a problem finding a solution in the <a href="http://developer.qt.nokia.com/doc/qt-4.8/qtreewidget.html#currentItem" rel="nofollow noreferrer">Qt Documentation On the QTreeWidgetItem</a>. I currently have an interface that has buttons to edit, delete, and copy instances in my <code>QTree</code>. It might be important for you to understand the way my tree is populated. The items displayed in the <code>QTree</code> are dynamically appended from a vector in this way. </p>
  
  <pre><code>void InjectionGUI::addInjections_Clicked() //creates a new instance of injections
  {
      InjectionDialog newAddInjectionDialog; //where my dialog opens for user input
      InjectionData defaultValues; 
      newAddInjectionDialog.setData(defaultValues);
              if(newAddInjectionDialog.exec() == QDialog::Accepted)//a check data returns either Accepted or rejected 
              {
                 qTableInjectionData.append(newAddInjectionDialog.transInjectionData); //this appends the valid data from the injection dialog to the vector qTableInjectionData
                  ui-&gt;injectionTreeWidget-&gt;clear();
                  for (int i=0; i &lt; qTableInjectionData.size(); i++) // here I add the data from the vector to the tree widget.
                      {
                      InjectionData temp = qTableInjectionData.at(i);
                          QString injectionType;
                          QString tmpStr;
                          int column = 0;
  
                          //need sorting solution(still working on this)
                          if(temp.particleInjectionActive == true) // this evaluates the injection types
                          {
                              if(temp.particleInjectionOrLiquidDroplets == true)
                              {
                                  injectionType += "(LD)";
                              }
                              else
                              {
                                  injectionType += "(P)";
                              }
                          }
                          if(temp.fluidInjectionActive == true)
                          {
                              injectionType += "(F)";
                          }
                          QTreeWidgetItem *qTreeWidgetItemInjectionData = new QTreeWidgetItem(ui-&gt;injectionTreeWidget); //Here data is added into rows from each instance of injection dialog found in vector
                          qTreeWidgetItemInjectionData-&gt;setText(column++, tmpStr.setNum(i));
                          qTreeWidgetItemInjectionData-&gt;setText(column++, temp.lineEditInjectionName);
                          qTreeWidgetItemInjectionData-&gt;setText(column++, injectionType);
                          qTreeWidgetItemInjectionData-&gt;setText(column++, tmpStr.setNum(temp.lineEditParitcleVelocity));
                          qTreeWidgetItemInjectionData-&gt;setText(column++, tmpStr.setNum(temp.lineEditFluidVelocity));
                          qTreeWidgetItemInjectionData-&gt;setText(column++, tmpStr.setNum(temp.lineEditParticleMassFlow));
                          qTreeWidgetItemInjectionData-&gt;setText(column++, tmpStr.setNum(temp.lineEditFluidMassFlow));
                          qTreeWidgetItemInjectionData-&gt;setText(column++, temp.lineEditComment);
                      }
              }
  }
  </code></pre>
  
  <p>Now I really need a way to find out which item the user has selected in the <code>QTree</code> so that I can have it deleted from the Vector. My psuedo is to identify which row has been selected, confirm delete, delete itemAt(item selected), reassign ID column; because each instance is assigned a number in this column. I was looking over this <a href="https://stackoverflow.com/questions/334952/how-can-i-find-the-selected-item-in-a-qtreewidget">post</a>, posted three years ago; but it mostly just refers back to the documentation that I have already been reviewing. Plus, the answer that was selected seems extremely inconclusive as the other answer seem to have been on the right track. I understand that this answer might be right in front of me here; but what can i say, noobs will be noobs and I am having a hard time understanding the implementation. Please only leave productive feedback as I am only interested in learning and accomplishing this task. Thanks in advanced. </p>