Results 1 to 2 of 2

Thread: item removement bugs to QListWidget

  1. #1
    Join Date
    Nov 2008
    Posts
    5

    Default item removement bugs to QListWidget

    When I am to clear the QListWiget variant listWidget, a rather strange bugs occur.

    first of all, I used the clear() method of QListWidget, it failed.
    listWidget->clear();

    then, I tried the takeItem() way, it failed again.
    for (int i = 0; i < listWidget->count(); i++)
    {
    QListWidgetItem *item = listWidget->takeItem(0);
    delete item;
    }

    after debugging step by step, I found that, the removing process goes well until it comes to the last item case. the QListWidgetItem *item = listWidget->takeItem(0); sentence failed with the accessing bugs.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: item removement bugs to QListWidget

    first of all, I used the clear() method of QListWidget, it failed.
    Qt Code:
    1. listWidget->clear();
    To copy to clipboard, switch view to plain text mode 
    and what does it mean 'failed'? Can you explain it? Application crashed? Or maybe there were remaining items to delete?

    And this:
    then, I tried the takeItem() way, it failed again.
    Qt Code:
    1. for (int i = 0; i < listWidget->count(); i++)
    2. {
    3. QListWidgetItem *item = listWidget->takeItem(0);
    4. delete item;
    5. }
    To copy to clipboard, switch view to plain text mode 
    should fail as count() is changing while taking item so it will remove only half of items.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Help on QListWidget InternalMove item signal
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 14th February 2009, 02:13
  2. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 12:59
  3. Replies: 1
    Last Post: 19th April 2007, 23:23
  4. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 20:41
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 10:56

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.