Results 1 to 3 of 3

Thread: QTreeWidgetItem Subclassing

  1. #1
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTreeWidgetItem Subclassing

    Hi, I want to subclass QTreeWidgetItem and use it within a QTreeWidget subclass, but I do not want to reimplement all functions from QTreeWidgetItem nore QTreeWidget.

    So far so god.

    Additionally I need the option to dynamically update the TreeWidget.

    I create a method to search for applicable TreeWidgetItems:



    Qt Code:
    1. /*! search from root (if root is zer0, search all nodes) all children for the Desired Drawable
    2.  */
    3. TreeWidgetItem* TreeWidget::deepSearchByPtr(TreeWidgetItem *root, Drawable *d){
    4. qDebug() << "DFS 0";
    5. if (root == 0){
    6. }
    7. else if (reinterpret_cast<Drawable*>(root->ptr()) == d){
    8. qDebug() << "DFS B";
    9. return root;
    10. }
    11.  
    12. qDebug() << "DFS C";
    13. TreeWidgetItem *ret;
    14. TreeWidgetItem *child;
    15. qDebug() << "DFS D";
    16. int count(0);
    17. if (root==0){
    18. count = invisibleRootItem()->childCount();
    19. }
    20. else{
    21. count = root->childCount();
    22. }
    23. for(int q(0); q<count; ++q){
    24. qDebug() << "DFS LOOP A";
    25. child = reinterpret_cast<TreeWidgetItem*>(root->child(q));
    26. qDebug() << "DFS LOOP B";
    27. if (child == NULL){
    28. qDebug() << "DFS LOOP C";
    29. continue;
    30. }
    31. qDebug() << "DFS LOOP D";
    32. ret = deepSearchByPtr(child, d);
    33. qDebug() << "DFS LOOP E";
    34. if (ret != NULL){
    35. qDebug() << "DFS LOOP F";
    36. return ret;
    37. }
    38. }
    39.  
    40. return NULL;
    41. }
    To copy to clipboard, switch view to plain text mode 

    The Problem with that is, that it fails right before
    Qt Code:
    1. qDebug() << "DFS LOOP B";
    To copy to clipboard, switch view to plain text mode 
    though all children actually are TreeWidgetItem s.

    Note: falling back to QTreeWidgetItems is not an option, as they hold way more data than ptr.

    Note:
    My Custom Type is called "TreeWidgetItem" and "TreeWIdget"

    can anybody plx help me to fix this issue.

    Sincerely

    soxs060389

    P.S. allready wasted hours on that subject...

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem Subclassing

    your code allows
    child = reinterpret_cast<TreeWidgetItem*>(root->child(q));

    to be called even if 'root == NULL'.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    soxs060389 (14th January 2010)

  4. #3
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidgetItem Subclassing

    Thank you very much, it was definitly too late to search for bugs yesterday O.o

    Solved

Similar Threads

  1. Replies: 4
    Last Post: 30th September 2009, 11:59
  2. Subclassing QTableView
    By T4ng10r in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 09:31
  3. Replies: 3
    Last Post: 26th April 2008, 18:42
  4. Subclassing QSortFilterProxyModel
    By r366y in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2006, 15:26
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 14:06

Tags for this Thread

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.