c++ - loop QHash by insert order -
Is it possible to make a coup to loop by the inclusion order? The method below seems to havehish with some other factors:
  QHashIterator & lt; QString, QString & gt; I (hash); While (i.hasNext ()) {i.next (); QDebug () & lt; & Lt; I.key () & lt; & Lt; ":" & Lt; & Lt; I value(); }    Edit:    I thought it was impossible with QUTS, but what should I use instead?   
 
  By documentation,  
  QHash is unordered, so  The order of an iterator can not be considered as expected . If the command is required by the key, then use   , so it is  not possible .   If you want an order based on keys, then  QMap  instead .. 
  Hope it helps .. 
  Edit: 
  If you need  no   key  and  value  logical mapping and just their value, You can 
   QList < QPair & lt; QString, QString & gt; & Gt; Couples; For example:   The first value can be obtained by  
  QString firstValue = pairs.at (0). first;  
  Similarly for the second value in QPair, 
   the second line = pairs.at (0) .second;  
  and you can iterate on  QList   to retrieve the elements in the order you entered. 
 
  
 
  
Comments
Post a Comment