Hi,

I'm trying create a QTreeWidgetList with multiple parents
root->parent->another parent->item

I'm adding the items by traversing through the already added parents and selecting the correct one by searching after the name of the parent. This works good until I try to add items to "another parent" then it returns null even if it have found correct parent node. Can anyone help me figure out what is happening?


Qt Code:
  1. QTreeWidgetItem* LabelingWidgetQt::iterateTreeWidget(QTreeWidgetItem* parent, QString str)
  2. {
  3. int count = parent ? parent->childCount() : treeWidget_->topLevelItemCount();
  4.  
  5. for (int i = 0; i < count; i++)
  6. {
  7. QTreeWidgetItem* item = parent ? parent->child(i) : treeWidget_->topLevelItem(i);
  8.  
  9.  
  10. if(item->text(0)==str){
  11. return item;
  12. }
  13.  
  14. iterateTreeWidget(item,str);
  15. }
  16. return 0;
  17. }
To copy to clipboard, switch view to plain text mode 

Here I create the Item and adds it to the found parent node.

Qt Code:
  1. item->setText(0, QString::fromStdString(name));
  2.  
  3. QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent));
  4. if(parentItem){
  5. parentItem->addChild(item);
  6. }
To copy to clipboard, switch view to plain text mode 

I'm using the same iterate method to add the parents/groups and this works fine and I can have multiple parents, but I cannot add items to the multiple parents, only to the topLevelItems.

Qt Code:
  1. QTreeWidgetItem* groupItem;
  2.  
  3. if(parent == "root"){
  4. groupItem = new QTreeWidgetItem(treeWidget_);
  5. groupItem->setText(0, QString::fromStdString(name));
  6. } else {
  7. QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent));
  8. groupItem = new QTreeWidgetItem(parentItem);
  9. groupItem->setText(0, QString::fromStdString(name));
  10. }
To copy to clipboard, switch view to plain text mode 

Thanks for any help!