Results 1 to 5 of 5

Thread: [SOLVED] Deleting an item from QTreeWidget

Threaded 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 [SOLVED] Deleting an item from QTreeWidget

    Well, I'm confused a little: I'm trying to delete selected item from QTreeWidget (in my case it have multiple columns) and always my app crashes on this action. Sorry for asking this question again and again, but I realy can't understand where my mistake is. Here are couple of solutions I've tryed (please, forgive me my english):

    Qt Code:
    1. QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
    2. if (!items.isEmpty()) {
    3. foreach (QTreeWidgetItem *item, items)
    4. delete item;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QTreeWidgetItem *twi = ui->treeWidget->currentItem();
    2. delete twi;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QTreeWidgetItem *parent = ui->treeWidget->currentItem()->parent();
    2. int index;
    3.  
    4. if (parent) {
    5. index = parent->indexOfChild(ui->treeWidget->currentItem());
    6. delete parent->takeChild(index);
    7. } else {
    8. index = ui->treeWidget->indexOfTopLevelItem(ui->treeWidget->currentItem());
    9. delete ui->treeWidget->takeTopLevelItem(index);
    10. }
    To copy to clipboard, switch view to plain text mode 

    I've tryed to set focus on another item before call "delete" but with no result... Please, any help. I started to code with Qt/C++ a couple of weeks ago and many things looks difficult to me.
    Last edited by xsid; 29th December 2014 at 21:15.

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.