Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97535

Bug in examples for QListIterator Class

    XMLWordPrintable

    Details

    • Platform/s:
      All

      Description

      In the documentation of QListIterator (https://doc.qt.io/qt-5/qlistiterator.html#details)
      we can see :

      QList<float> list;
      ...
      QListIterator<float> i(list);
      while (i.hasNext())
          qDebug() << i.next();
      

      or

      QListIterator<float> i(list);
      i.toBack();
      while (i.hasPrevious())
          qDebug() << i.previous();
      

      These codes fail depending on the debug level. If "*.debug=false", methods next() or previous() are not executed in the examples above. And the loop is infinite if there is at least one element.

      So we have to prefer :

       QList<float> list;
      ...
      QListIterator<float> i(list);
      while (i.hasNext()) {
          float value = i.next();
          qDebug() << value;
      }
      

      and

      QListIterator<float> i(list);
      i.toBack();
      while (i.hasPrevious()) {
          float value = i.previous()
          qDebug() << value;
      }
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            docteam Qt Documentation Team
            Reporter:
            romuald Romuald DELAVERGNE
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes