I have browsed the documentation, but didn't find one. Any ideas?
A:
By now I have the following:
//filter out duplicates: stl algorithm 'unique' would be useful here
QList<int> uniqueIDs;
qStableSort(res);
foreach(int id, res)
if ( (uniqueIDs.empty())
|| (uniqueIDs.back() != id))
uniqueIDs.push_back(id);
swap(res, uniqueIDs);
res being the input for filtering, and not pleased with it.
MadH
2009-10-15 11:46:57
+5
A:
You should be able to just apply std::unique
to the iterators of QList
. std::unique
just requires the iterators to be forward iterators (here and here), and it appears that QList
's iterators meet that requirement.
blwy10
2009-10-15 11:52:17
well, it also requires compiling Qt with STL support (which so far wasn't needed)
MadH
2009-10-15 12:35:44
+1 but true, std::erase + std::unique should work just fine
MadH
2009-10-15 12:36:21
+1
A:
Consider using a QSet
instead (and use QSet::toList
when you need it as a list).
Intransigent Parsnip
2009-10-15 13:28:26
set is good idea. The only reason I'm using list is that it's easier to add items (and there are thousands of them collected by a breath first search).
MadH
2009-10-15 14:01:02