Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: Having trouble clearing a QTreeWidget.

  1. #21
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Hello,

    I've re-configured and re-built Qt in debug mode.

    I've tested my code under GDB and I got the same backtrace as before (the one in the above message).

    I've tested your code under GDB and I got the following backtrace :
    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    9. (gdb) run
    10. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    11. warning: ITEMS SELECTED: 1
    12.  
    13. warning: ITEMS SELECTED: 0
    To copy to clipboard, switch view to plain text mode 
    At this step the QTeeWidget is cleared and the application crashed.

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    So as you see there are no items selected so you can't call at(0). You have to redesign the method.

  3. #23
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Yes, but I still don't understand the problem.

    void QTreeWidget::itemSelectionChanged () [signal]
    This signal is emitted when the selection changes in the tree widget. The current selection can be found with selectedItems()
    It appears that the signal itemSelectionChanged() has been emited 2 times. This is strange... The first time we have 1 item selected : that's OK, I select 1 item in the QTreeWidget. But why is the list empty ?! It should contains the item, like it is described in the Assistant :

    QList<QTreeWidgetItem *> QTreeWidget::selectedItems () const
    Returns a list of all selected non-hidden items.
    See also itemSelectionChanged().
    So I can't understand :
    - Why the signal has been emited 2 times (1 just clic 1 item, 1 time, with 1 clic)
    - Why the function isEmpty() returns "true", where as count() returns "1".

    Have you got an idea ?

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    If isEmpty() returns true, count() has to return 0. There is no other way, you must be messing something up. I can't say why the selection is empty in your case - maybe you are mixing the selected and the current item? Current item doesn't have to be selected...

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

    Nyphel (10th October 2007)

  6. #25
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    With this code for my SLOT :
    Qt Code:
    1. void interface_impl::SLOT_selection_changed()
    2. {
    3. QString item_name;
    4.  
    5. QList<QTreeWidgetItem*> sel = tree->selectedItems();
    6. qDebug("ITEMS SELECTED: %d", sel.count());
    7.  
    8. if(!sel.isEmpty())
    9. {
    10. item_name = sel.at(0)->text(0);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    I get the following backtrace :
    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    9. (gdb) run
    10. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    11. warning: ITEMS SELECTED: 1
    12.  
    13.  
    14. Program exited normally.
    15. (gdb)
    To copy to clipboard, switch view to plain text mode 

    So now the QTreeWidget isn't cleared and the signal isn't emited a second time. That's OK.
    And, if I'm right :
    - 1 select an item : the signal is emited and the slo is performed
    - "tree->selectedItems();" returns 1 QTreeWidgetItem* in the list
    - "count()" confirms that there is 1 item in the list
    - "isEmpty()" returns "TRUE", indicating that the list is empty

    Like "tree->selectedItems();" returns a QList of selected items, I suppose I never take care about current item :s

  7. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    It is "!isEmpty()", so it negates the result.

  8. #27
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Yes of course
    Like "isEmpty()" returns TRUE, "!isEmpty()" returns FALSE and the instruction "item_name = sel.at(0)->text(0);" is performed, like shown on the backtrace... This is my problem.

    I can't understand how this QList can be empty with an item inside of it...

  9. #28
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble clearing a QTreeWidget.

    Oh I'm so stupid... What am I saying... All works well...
    Sorry Wysota ^_^

    To conclude, here is my last backtrace showing that there is no more problem.

    Qt Code:
    1. void interface_impl::SLOT_selection_changed()
    2. {
    3. QString item_name;
    4.  
    5. QList<QTreeWidgetItem*> sel = tree->selectedItems();
    6. qDebug("COUNT: %d", sel.count());
    7. qDebug("SIZE: %d", sel.size());
    8. qDebug("EMPTY: %d", sel.isEmpty());
    9.  
    10. if(sel.isEmpty() == false)
    11. {
    12. qDebug("item_name : before acces");
    13. item_name = sel.at(0)->text(0);
    14. qDebug("item_name : after acces");
    15. }
    16.  
    17. qDebug("tree : before clear");
    18. tree->clear();
    19. qDebug("tree : after clear");
    20. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    9. (gdb) run
    10. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    11.  
    12. warning: COUNT: 1
    13.  
    14. warning: SIZE: 1
    15.  
    16. warning: EMPTY: 0
    17.  
    18. warning: item_name : before acces
    19.  
    20. warning: item_name : after acces
    21.  
    22. warning: tree : before clear
    23.  
    24. warning: COUNT: 0
    25.  
    26. warning: SIZE: 0
    27.  
    28. warning: EMPTY: 1
    29.  
    30. warning: tree : before clear
    31.  
    32. warning: tree : after clear
    33.  
    34. warning: tree : after clear
    35.  
    36.  
    37. Program exited normally.
    38. (gdb)
    To copy to clipboard, switch view to plain text mode 

    Like it has been recommanded me on Qtfr forums, I should use the accessors "value()" or "take()" instead of "at()" in order to prevent segmentation fault errors . This would have help us so much...
    Last edited by Nyphel; 10th October 2007 at 15:22.

  10. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Having trouble clearing a QTreeWidget.

    Quote Originally Posted by Nyphel View Post
    Like it has been recommanded me on Qtfr forums, I should use the accessors "value()" or "take()" instead of "at()" in order to prevent segmentation fault errors . This would have help us so much...
    I don't think it would help. Your problem was that you were dereferencing a pointer without checking it for null first.

Similar Threads

  1. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.