Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeWidget Delete Last Item
Qt 6.11 is out! See what's new in the release blog

QTreeWidget Delete Last Item

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ARASHz4
    wrote on last edited by
    #1

    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 :

    ui->TreeWidget->takeTopLevelItem(currentItem);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have a stack trace ?

      Are you sure currentItem is valid ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you have a stack trace ?

        Are you sure currentItem is valid ?

        A Offline
        A Offline
        ARASHz4
        wrote on last edited by
        #3

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

        ui->TreeWidget->takeTopLevelItem(0);
        

        and app crash

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rondog
          wrote on last edited by Rondog
          #4

          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:

          	while(d_machine_parameter_tree->topLevelItemCount())
          	{
          		d_machine_parameter_tree->takeTopLevelItem(0);
          	}
          

          Qt 5.6.0, OSX 10.10.5

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved