PDA

View Full Version : remove struct from qlist



mero
26th October 2012, 12:11
Hello,

How can I remove struct from Qlist ?

example (not working)


struct nick { QString name; QString subname; };
QList<nick> nicklist;

foreach (nick n, nicklist)
{
if (n.name == "testname")
{
nicklist.removeOne(n);
break;
}
}

Zlatomir
26th October 2012, 13:22
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.

Brecht
26th October 2012, 14:58
Drop the foreach and use a for with an index (or an iterator)


for(int i = 0; i < nickList.count(); ++i) {
if(nicklist.at(i).name == "fons") {
nickList.removeAt(i);
break;
}
}