Results 1 to 3 of 3

Thread: remove struct from qlist

  1. #1
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default remove struct from qlist

    Hello,

    How can I remove struct from Qlist ?

    example (not working)
    Qt Code:
    1. struct nick { QString name; QString subname; };
    2. QList<nick> nicklist;
    3.  
    4. foreach (nick n, nicklist)
    5. {
    6. if (n.name == "testname")
    7. {
    8. nicklist.removeOne(n);
    9. break;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: remove struct from qlist

    Why don't you tell us what the problem actually is?

    I assume you can't use removeOne without operator== for your struct, because the compiler doesn't generate that you need to define it yourself, but this is just a guess... you need to tell us more information about your problem/error you get.

  3. #3
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: remove struct from qlist

    Drop the foreach and use a for with an index (or an iterator)

    Qt Code:
    1. for(int i = 0; i < nickList.count(); ++i) {
    2. if(nicklist.at(i).name == "fons") {
    3. nickList.removeAt(i);
    4. break;
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QList<struct>
    By Axsis in forum Newbie
    Replies: 11
    Last Post: 12th October 2015, 08:48
  2. Replies: 6
    Last Post: 22nd March 2011, 16:17
  3. How to fill a QList<struct> ?
    By falconium in forum Newbie
    Replies: 1
    Last Post: 1st March 2011, 22:59
  4. Remove widget from a QList
    By Eos Pengwern in forum Newbie
    Replies: 4
    Last Post: 16th October 2009, 22:25
  5. Remove first n elements from QList
    By pakulo in forum Qt Programming
    Replies: 8
    Last Post: 4th June 2007, 08:27

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.