Results 1 to 8 of 8

Thread: QTreeWidget->clear() causing crash after sort

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget->clear() causing crash after sort

    There is quite a bit of code, as the subclass is for drag and drop. It would probably be easier to give a url to the project...

    But, I found it was caused by the signal currentItemChanged(current, previous), or just the way I was using it. I only made reference to current, and a quick "if (current)" fixed the problem. But why would the current item be null in one sort order but not the other? Is this a Qt Bug?

  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->clear() causing crash after sort

    I think the selection might be cleared when sort order changes.
    Have you checked that?

  3. #3
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget->clear() causing crash after sort

    I have not checked in code, but visually, the same line is highlighted when sort order is changed.

    I can see how as items are removed, the selected item could be cleared. But why would it be different between sort orders? It is only the Descending sort order that I get the null current item, with or without a selection. It seems like it should happen in both sort orders or neither.

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

    Default Re: QTreeWidget->clear() causing crash after sort

    Where exactly do you call clear()?

  5. #5
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget->clear() causing crash after sort

    Quote Originally Posted by wysota View Post
    Where exactly do you call clear()?
    In a refresh() function in the QDialog that contains the Tree. It's called when the app loads to initially populate the tree, and is then connected to a button to refresh the list at any time.

    Clearing the list and iterating through a plugin list seems the easiest way to refresh, rather than checking for additions or deletions.

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

    Default Re: QTreeWidget->clear() causing crash after sort

    When you clear the widget, all its items will become invalid, so if you store a pointer to one (or more) of them somewhere, you can't use it anymore - you have to ask the widget for the item again. Because you never know what caused a slot to trigger, you should always check for validity of pointers you get as slot parameters.

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.