Hi all
Working on Qt 4.4.2 on my intel mac machine.
Pls tell How to remove duplicate enteries from QStringList.
Hi all
Working on Qt 4.4.2 on my intel mac machine.
Pls tell How to remove duplicate enteries from QStringList.
Always Believe in Urself![]()
Merry
if you do not care about the order of the list:
Qt Code:
QStringList sl = ...; sl = sl.toSet().toList();To copy to clipboard, switch view to plain text mode
Maybe there are more efficient ways to do that.
Or you could do
Untested, of course. Have, fun!Qt Code:
for (int i=0; i<sl.count(); ++i) { forever { // remove all occurrences at greater indexes int p=sl.lastIndexOf(sl.at[i]); if (p==i) break; sl.removeAt(p); } }To copy to clipboard, switch view to plain text mode
merry (11th December 2008)
QStringList has a remove duplicates
QStringList::removeDuplicates()
Wow! Only 11 years to give us a solution.
Òscar Llarch i Galán
Do you know how long I have been sitting here waiting for this answer? Now I can finally finish my project!
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Yes! I can sleep now.
Òscar Llarch i Galán
Bookmarks