Quote Originally Posted by wysota View Post
You would.

Yes, of course. For instance like so:

Qt Code:
  1. QHash<int, int> m_lookupIndex; // maps id to index in the list
  2. struct Item{
  3. int id;
  4. int count;
  5. Item(){id=-1;count=0;}
  6. };
  7. QList<Item> m_data;
  8.  
  9. void Model::insert(...){
  10. int id = getId();
  11. Item item;
  12. item.id = id;
  13. item.count = 1;
  14. int index = m_data.count();
  15. m_list.append(item);
  16. m_lookupIndex[id] = index;
  17. //...
  18. }
  19.  
  20. QModelIndex Model::idToIndex(int id){
  21. if(!m_lookupIndex.contains(id))
  22. return QModelIndex();
  23. int ind = m_lookupIndex[id];
  24. // it'd be 2 times faster using iterators, but it's just an example, so...
  25. return index(ind, 0);
  26. }
To copy to clipboard, switch view to plain text mode 
fuh you got me confused I must say ...thanks anyway