Important: Please read the Qt Code of Conduct -

QTreeWidget Delete Last Item

  • hi
    when QTreeWidget just have 1 item & if i want delete the item application crash & when have more than 1 item work fine, this is my code :


  • Lifetime Qt Champion


    Do you have a stack trace ?

    Are you sure currentItem is valid ?

  • @SGaist Hi
    No, i don't have stack trace & currentItem is valid even i test whit this code when i have only 1 item:


    and app crash

  • Maybe there is some side effect even that happens which is actually the source of the crash. For example, you might have a problem if you don't handle the signal itemSelectionChanged() properly (i.e. you don't expect a no-selection case).

    I tried this without problems:


    Qt 5.6.0, OSX 10.10.5

    Note: You should delete the returned widget otherwise it is a memory leak.

Log in to reply