开发者

std::unique analogue in Qt?

I have browsed the documentation, but开发者_StackOverflow didn't find one. Any ideas?


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.


Consider using a QSet instead (and use QSet::toList when you need it as a list).


This is how I created my unique list of integers:

list=QSet::fromList(list).toList();

No need to add STD, it might not be the best way using very large integers though


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜