"When iterating over a QHash <http://qt-project.org/doc/qt-5/qhash.html>, the items are arbitrarily ordered. With QMap, the items are always sorted by key."

from: http://qt-project.org/doc/qt-5/qmap.html#details


On 06/11/2014 01:36, Robert Steckroth wrote:
Consider the following program, shouldn't the end() iterator place each key at the end of the newly created QMap. Instead, the keys and subsequent iterations are sorted (somehow).

#include  <QCoreApplication>
#include  <QMap>
#include  <QString>
#include  <QDebug>
int  main(int  argc,  char  *argv[])
{
     QCoreApplication  a(argc,  argv);
     QMap  <QString,  QString>  m;
     m.insertMulti(m.end(),  "2",  "22");
     m.insertMulti(m.end(),  "1",  "11");
     m.insertMulti(m.end(),  "3",  "33");
     QMap<QString,  QString>::iterator  i  =  m.begin();
     for  (  i  =  m.begin();  i  !=  m.end();  ++i  )  {
         qDebug()  <<  ">"  <<  i.key();
     }
     qDebug()  <<  ":"  <<  m.keys();
     return  a.exec();
}
/*  OUTPUT:
  *
  *  >  "1"
  *  >  "2"
  *  >  "3"
  *  :  ("1",  "2",  "3")
  *
  */

--
<surgemcgee>





_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to