Results 1 to 4 of 4

Thread: Howto remove row from QListWidget

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Howto remove row from QListWidget

    I tried the following to remove a row from the list

    Qt Code:
    1. int row = listWidgetVideo->currentRow();
    2. listWidgetVideo->removeItemWidget(listWidgetVideo->item(row));
    To copy to clipboard, switch view to plain text mode 

    but nothing happens.

    How do I do this correct?

    EDIT:
    seems to be
    Qt Code:
    1. listWidgetVideo->takeItem(row);
    To copy to clipboard, switch view to plain text mode 
    Last edited by pospiech; 29th July 2008 at 20:25.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [solved] Howto remove row from QListWidget

    Notice that takeItem() takes the item away from the tree and returns it. The item is NOT deleted. You are responsible for deleting it yourself (calling takeItem() without handling the return value will lead to a memory leak). One can also fairly well just directly delete an item and the item will be properly removed from the list. The takeItem() method was mainly provided for cases when you need to take an item temporarily away from the list but keep it alive so that it can be restored later.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [solved] Howto remove row from QListWidget

    Quote Originally Posted by jpn View Post
    Notice that takeItem() takes the item away from the tree and returns it. The item is NOT deleted. You are responsible for deleting it yourself (calling takeItem() without handling the return value will lead to a memory leak). One can also fairly well just directly delete an item and the item will be properly removed from the list. The takeItem() method was mainly provided for cases when you need to take an item temporarily away from the list but keep it alive so that it can be restored later.
    From all you say I only understand two things which leave me with even more questions.

    1. I do not delete the item with takeItem(). But how do I delete it?
    2. Real deletion without takeItem() works different. But how?

  4. #4
    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: [solved] Howto remove row from QListWidget

    Quote Originally Posted by pospiech View Post
    I do not delete the item with takeItem(). But how do I delete it?
    By calling delete on it. And you don't have to take it out of the list before you do that.

Similar Threads

  1. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 14:25
  2. Replies: 13
    Last Post: 15th December 2006, 12:52
  3. Replies: 1
    Last Post: 24th August 2006, 12:44
  4. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 09:58

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.