Results 1 to 5 of 5

Thread: Retrieveing data from QTreeWidgetItem

Hybrid View

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

    Default Re: Retrieveing data from QTreeWidgetItem

    Also, I'm having a little trouble traversing my tree. Any suggestions??
    There are a few threads about this. You should search the forum. I answered one of them myself.
    The idea is to create a recursive function that traverses the tree.

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

    db (19th October 2007)

  3. #2
    Join Date
    Feb 2007
    Posts
    48
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6

    Default Re: Retrieveing data from QTreeWidgetItem

    OK. Now I have the tree created using the above referenced code. And I figured out how to traverse it. Problem is when I try to print the data from the node I get nothing. Just the “method: “ portion.

    Where did I go wrong??

    Also when the lower node is “checked” what kinf of even is generated? I want to be able to do some processing when that occurs.

    Thanks, again

    Qt Code:
    1. void CTREEcu::processTree()
    2. {
    3.  
    4. // loop through all branches and nodes of the tree and diaplay its text
    5. for ( int i=0; i< twMain->topLevelItemCount(); i++)
    6. {
    7. QTreeWidgetItem *item = twMain->topLevelItem(i);
    8.  
    9. qDebug("PARENT - idx: %d text: %s",i,qPrintable(item->text(0)));
    10.  
    11. processItem(item);
    12. }
    13.  
    14. }
    15.  
    16. void CTREEcu::processItem(QTreeWidgetItem * parent)
    17. {
    18.  
    19. for (int i=0; i< parent->childCount(); i++)
    20. {
    21. QTreeWidgetItem *child = parent->child(i);
    22. qDebug("CHILD - idx: %d text: %s",i,qPrintable(child->text(0)));
    23. if ( child->checkState(0) == Qt::Checked )
    24. {
    25.  
    26. qDebug("CHILD - THIS ONE IS CHECKED");
    27. child->setCheckState(0,Qt::Unchecked);
    28.  
    29. // this piece of code can be used to set a marker for the current checked
    30. // item so it is not erased
    31. QModelIndex idx = twMain->currentIndex();
    32. qDebug("internalId: %ld",idx.internalId());
    33.  
    34. // print out sample data
    35. QMap<QString,QVariant> nodeData = child->data(0,Qt::UserRole).toMap();
    36. qDebug("method: %s",qPrintable(nodeData.value("method").toString()));
    37. }
    38. processItem(child);
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 19th October 2007 at 20:54. Reason: missing [code] tags

Similar Threads

  1. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  2. How to store/get pointer on QTreeWidgetItem data?
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2007, 22:26
  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
  •  
Qt is a trademark of The Qt Company.