[Development] Is QMap Broken

Renaud Guezennec renaud.guezennec at gmail.com
Thu Nov 6 01:53:53 CET 2014


"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
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141106/d2dde13c/attachment.html>


More information about the Development mailing list