@Bart
Hi,
please
put
QHash<QString, QTreeWidgetItem * > Parents;
outside the for loop.
Also,
you say
if(blades.contains(ArraySet1[i][0]))
Should that not be Parents?
Anyway, when Contains is true, you do not create a new QTreeWidgetItem but instead use the one you store in the
hash list. that way you will connect to the same Parent (the first one) when you see the same name again.
We use the list to keep track of ParentName, and the QTreeWidgetItem that we created with that name.
so
if(blades.contains(ArraySet1[i][0]))
{
QTreeWidgetItem *y = new QTreeWidgetItem();
y>setText(0,ArraySet1[i][1]);
x->addChild(y); <----------------- x here should be the parent you stored in the hash list
}
becomes
if(Parents.contains(ArraySet1[i][0]))
{
QTreeWidgetItem *NewChild = new QTreeWidgetItem();
NewChild>setText(0,ArraySet1[i][1]);
QTreeWidgetItem *StoredParent =Parents.value(ArraySet1[i][0]);
StoredParent ->addChild(NewChild)
} else
{
// create the new parent and store in list
QTreeWidgetItem *x = new QTreeWidgetItem(ui->treeWidget);
x->setText(0,ArraySet1[i][0]);
ui->treeWidget->addTopLevelItem(x);
Parents->Insert( ArraySet1[i][0], x ); // store our parent under that name
QTreeWidgetItem *y = new QTreeWidgetItem();
y->setText(0,ArraySet1[i][1]);
x->addChild(y);
QTreeWidgetItem *z = new QTreeWidgetItem();
z->setText(0,ArraySet1[i][2]);
y->addChild(z);
l
}
something like that. Hope it makes sense.
ps. did not try to compile so might be syntax errors.