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

REG Qt 6.0: QList/QVector::fill does not support shrinking list

    XMLWordPrintable

    Details

    • Platform/s:
      All
    • Commits:
      6512a7fc642c65455db770385c67cfa6d71c294c (qt/qtbase/dev) dca5a2ca39d45ec7ac1472f438328b3b941bcad1 (qt/qtbase/6.1) 249b3100466556ff56f04fbf063f977dbdccbda3 (qt/qtbase/6.0)

      Description

      QList::fill() (aka QVector::fill() in Qt 5.x) is documented to resize the list to the newSize parameter if this is >= 0.

      In Qt 6, it only resizes the list if the new size is larger than the old.

      The following example demonstrates (QVector used here to make it portable to Qt 5, but the same happens in Qt 6 if you use QList as well):

      #include <QtCore>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QVector<int> ints;
          ints.fill(123, 100);
          qDebug() << "Ints size:" << ints.size();
      
          ints.fill(123, 101);
          qDebug() << "Ints size:" << ints.size();
      
          ints.fill(123, 99);
          qDebug() << "Ints size:" << ints.size();
      
          return 0;
      }
      

      The final size of the list is 101, despite being resized to 99.

      This is cause of QTBUG-90437.

        Attachments

          Issue Links

          For Gerrit Dashboard: QTBUG-91042
          # Subject Branch Project Status CR V

            Activity

              People

              Assignee:
              thiago Thiago Macieira
              Reporter:
              esabraha Eskil Abrahamsen Blomfeldt
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes