Results 1 to 2 of 2

Thread: [solved] Deleting element form QList does not change count()

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default [solved] Deleting element form QList does not change count()

    Hi there,

    I have put several tasks in a QList and when the task is done it shall be deleted form the list. If I do
    Qt Code:
    1. iniTextList.removeFirst();
    2. ui->iniList->setModel(new QStringListModel(iniTextList));
    To copy to clipboard, switch view to plain text mode 
    the first element disappears but iniList.count(); still gives me the initial number of elements. I guess removeFirst() does not "shrink" the list, the list still got n values just the first is empty and therefore not displayed. Is there a way to shorten the list?

    [EDIT]
    Sorry for the post! I just realized that I was deleting elements from the view and counted the elements of the underlying list.
    Last edited by KeineAhnung; 4th May 2014 at 21:34.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [solved] Deleting element form QList does not change count()

    Just in case your code actually looks like that: this leaks string list models.

    Cheers,
    _

Similar Threads

  1. Can't change form element names after copying them
    By Computer Hater in forum Qt Tools
    Replies: 0
    Last Post: 8th July 2011, 03:24
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. Change a QList element
    By mcrahr in forum Newbie
    Replies: 1
    Last Post: 23rd August 2009, 11:16
  4. deleting all elements in a qlist
    By reshma in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2009, 20:27
  5. QList<myObject*> myObjectList count() error
    By morty in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2006, 15:08

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.