Results 1 to 8 of 8

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

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

    Default QTreeWidget->clear() causing crash after sort

    I have a subclassed QTreeWidget that crashes the application when clear() is called after clicking a column header to change the sort order. It works repeatedly when the sort order is not changed, but once changed it crashes immediatly. On Windows, it gives exit code 3.

    Anyone else experiencing this? I have no custom sorting of any kind, so I doubt it's my code, but could be.

    -Chuk

  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

    It could be your code.
    Can you post an example?

  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

    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?

  4. #4
    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?

  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

    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.

  6. #6
    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: QTreeWidget->clear() causing crash after sort

    Where exactly do you call clear()?

  7. #7
    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.

  8. #8
    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: 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.