Hi,

I already asked this question in another forum, but I'm not getting any answers,maybe you can help me.
by adding more than one item to my QTreeWidget my program fails to return the text of the 2nd, 3rd,... item. The QString it should return stays empty.

This is how it looks:
Unbenannt.png

I’m creating a QTreeWidgetItems and add them to a QTreeWidget in a QDockWidget called “targetInfoWidget_”.

Qt Code:
  1. bool ok;
  2. QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
  3. tr("Target Name:"), QLineEdit::Normal, "", &ok);
  4. if (ok && !text.isEmpty()) {
  5. QTreeWidgetItem *item = new QTreeWidgetItem(targetInfoWidget_->treeWidget);
  6. item->setText(0, text);
  7. }
To copy to clipboard, switch view to plain text mode 

and then I want to get the selected item in the tree and do stuff with it, depending on the found name of the item.

Qt Code:
  1. QTreeWidgetItem *item = targetInfoWidget_->treeWidget->currentItem();
  2. int col = targetInfoWidget_->treeWidget->indexOfTopLevelItem(item);
  3. QMessageBox::critical(this, "Col", QString::number(col));
  4. QString itemToAppendName = item->text(col);
  5. QMessageBox::critical(this, "item To Append", itemToAppendName);
To copy to clipboard, switch view to plain text mode 

The QMessageBoxes are for me to check what the results of the lines are and to get to know at which line the results are not correct anymore.

For the item asd the messages return “0” and “asd”. For the Item sdf the messages return “1” and what is shown in picture above.

I'm googling for days now without finding a solution.
Is someone out there who's able to help me?
btw. I'm using Visual Studio 12 to hardcode the Userinterface and not the QtCreator.