Hello,
How can I remove struct from Qlist ?
example (not working)
Qt Code:
QList<nick> nicklist; foreach (nick n, nicklist) { if (n.name == "testname") { nicklist.removeOne(n); break; } }To copy to clipboard, switch view to plain text mode
Hello,
How can I remove struct from Qlist ?
example (not working)
Qt Code:
QList<nick> nicklist; foreach (nick n, nicklist) { if (n.name == "testname") { nicklist.removeOne(n); break; } }To copy to clipboard, switch view to plain text mode
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.
Drop the foreach and use a for with an index (or an iterator)
Qt Code:
for(int i = 0; i < nickList.count(); ++i) { if(nicklist.at(i).name == "fons") { nickList.removeAt(i); break; } }To copy to clipboard, switch view to plain text mode
Bookmarks