Results 1 to 4 of 4

Thread: QTreeWidget - Parsing Data.

  1. #1
    Join Date
    Jun 2007
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeWidget - Parsing Data.

    Hi,

    I have a QTreeWidget. I need to parse data from it and write it to a file. Can some one tell me how to read QTreeWidgetItems from QTreeWidget.

    Please post some code if possible.

    Thanks..

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget - Parsing Data.

    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.
    Qt Code:
    1. void SomeClass::traverseTree(QTreeWidgetItem root)
    2. {
    3. if( root && root->childCount())
    4. {
    5. int childCount = root->childCount();
    6. for( int i = 0; i != childCount(); i++ )
    7. traverseTree( root->child(i);
    8. //Assuming you have any extra data in items that are not terminal nodes,
    9. //then you can save it here.
    10. }
    11. else if( !root->childCount() ) //this means it is a leaf
    12. {
    13. //save whatever data you have in your item in the file.
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    This should pretty much work.

    Regards

  3. #3
    Join Date
    Jun 2007
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget - Parsing Data.

    Hi,

    Thats seems good but how to get root node that i will pass to this function. Also i need to save Root node data as well as leaf node in file. Below is sample.

    *****RootNode1*****
    Leaf Node1
    Leaf Node2
    *****RootNode2*****
    Leaf Node1
    Leaf Node2

    Thanks...

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget - Parsing Data.

    You can obtain it with QTreeWidget::invisibleRootItem.
    You must call the method I've given you only once, with this item as parameter.

    Regards

  5. The following user says thank you to marcel for this useful post:

    Preeteesh (17th June 2007)

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  4. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.