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

Bug in examples for QListIterator Class

    XMLWordPrintable

Details

    • All
    • 713967ae30 (qt/qtbase/dev) 713967ae30 (qt/tqtc-qtbase/dev) 809f6c3637 (qt/qtbase/6.3) 809f6c3637 (qt/tqtc-qtbase/6.3) 510b82ea30 (qt/qtbase/6.2) 510b82ea30 (qt/tqtc-qtbase/6.2) 740c9e96de (qt/tqtc-qtbase/5.15)

    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

            kkohne Kai Köhne
            romuald Romuald DELAVERGNE
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes