Hi guys
I'm using qSort () to sort a QList<int> list.
Now I will hardcode it to remove any duplicate int's from QList.
Unless that there is some "magical" Qt function that I don't know about that does that for me
Thanks
Hi guys
I'm using qSort () to sort a QList<int> list.
Now I will hardcode it to remove any duplicate int's from QList.
Unless that there is some "magical" Qt function that I don't know about that does that for me
Thanks
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Search the QList doc for "duplicates".
john_god (22nd December 2010)
Thanks norobro
There is a
int QStringList::removeDuplicates ()
but only for QStringList
I need it for QList, it seems it's not available
Last edited by john_god; 22nd December 2010 at 21:05. Reason: updated contents
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Chromatix (4th September 2015)
Won't QList::toSet() do what you want?
... and QSet::toList() to regain a QList. But maybe a small function of yourown to remove duplicates is faster.
Thank you guys
I will check this later, but something like this should work
Qt Code:
QSet<int> set = m_hits_list.toSet(); m_hits_list = set.toList(); qSort(m_hits_list.begin(),m_hits_list.end());// sort the listTo copy to clipboard, switch view to plain text mode
Do you think Lykurg ? I will check for performance later, but I thought Qt functions were very optimized. I would problably do it with a for() and a removeAll(), don't know if would be faster.But maybe a small function of yourown to remove duplicates is faster.
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
If you need to remove duplicates, why allow the duplicates to the QList in the first place? Use QList::contains() to see if a value already exists in the list before adding it.
Bookmarks