One way is to create a recursive function that traverses the tree.
I assume you only want to save the data in the leaf nodes.
{
if( root && root->childCount())
{
int childCount = root->childCount();
for( int i = 0; i != childCount(); i++ )
traverseTree( root->child(i);
//Assuming you have any extra data in items that are not terminal nodes,
//then you can save it here.
}
else if( !root->childCount() ) //this means it is a leaf
{
//save whatever data you have in your item in the file.
}
}
void SomeClass::traverseTree(QTreeWidgetItem root)
{
if( root && root->childCount())
{
int childCount = root->childCount();
for( int i = 0; i != childCount(); i++ )
traverseTree( root->child(i);
//Assuming you have any extra data in items that are not terminal nodes,
//then you can save it here.
}
else if( !root->childCount() ) //this means it is a leaf
{
//save whatever data you have in your item in the file.
}
}
To copy to clipboard, switch view to plain text mode
This should pretty much work.
Regards
Bookmarks