Results 1 to 5 of 5

Thread: [SOLVED] Deleting an item from QTreeWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2014
    Location
    Balti, Republic of Moldova
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Deleting an item from QTreeWidget

    No, still crash with message "ASSERT failure in QList<T>::at: "index out of range"". What am I doing wrong? Crash appears even I'm trying to clear treeWidget and load data in it again, not just on item deleting.

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Deleting an item from QTreeWidget

    Then the problem is with foreach. Most likely, as you delete the list items, the indexing of items (crashing is QTreeWidget::at()) becomes invalid. I suggest while and using QList::takeFirst() as a more sure processing the list. takeFirst() removes the first item from the list and returns it (or it returns nullptr if the list is empty).

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

    xsid (29th December 2014)

  4. #3
    Join Date
    Dec 2014
    Location
    Balti, Republic of Moldova
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Deleting an item from QTreeWidget

    The problem was not in code. Every solutions above works. In the widget properties MUST be set selectionBehavior->SelectRows (I guess in case of multiple columns such mine case). Thank you, Radek, your code is very usefull and thanks for clarification about how to delete TreeWidget item correctly!
    Last edited by xsid; 29th December 2014 at 21:18.

Similar Threads

  1. Replies: 0
    Last Post: 21st October 2013, 09:16
  2. Problem while deleting item in QTreeView
    By QtNewbieNeedsHelp in forum Newbie
    Replies: 1
    Last Post: 4th September 2013, 06:46
  3. Replies: 0
    Last Post: 1st May 2012, 23:11
  4. Removing item from layout without deleting it.
    By mrc_pl in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2012, 11:24
  5. deleting first item in a list
    By soul_rebel in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 17:49

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
  •  
Qt is a trademark of The Qt Company.