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

QStringList, QList<QString> Iterator abnormal behavior

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.8.1
    • Other
    • None
    • Windows 10, Intel core i5 7th Gen.
    • Windows

    Description

      Following code works for some values of i (i is the quantity of string object inserted into the list) whilst does not work for others. When it does not work this error is shown:

      ASSERT failure in QList::insert: "The specified iterator argument 'before' is invalid", file  C:/Qt/6.8.1/llvm-mingw_64/include/QtCore/qlist.h, line 505 qtc.process_stub: Inferior: QProcess::Crashed "Process crashed".

      #include <QCoreApplication>
      #include <QString>
      #include <QList>
      #include <QTextStream>
      #include <QStringList>

      int main(int argc, char *argv[])
      {
         QCoreApplication a(argc, argv);

         QList<QString> list_string;
         QList<QString>::iterator list_it;

         //QStringList list_string;
         //QStringList::iterator list_it;

         QTextStream out(stdout);

       

         //functions with element number 1, 5, 6, 15, 16, ...
         //does not function with element number 2, 4, 6, 7, 8, 9, ...

         for(int i = 0; i < 5; i++)
         

      {       list_string.append("one");    }

         list_it = list_string.begin();
         while(list_it != list_string.end())
         {
            list_it++;
            if(list_it != list_string.end())
           

      {          list_string.insert(list_it, " and ");          list_it++;       }

         }

         list_it = list_string.begin();
         while(list_it != list_string.end())
         

      {       out << *list_it << Qt::endl;       list_it++;    }

         return a.exec();
      }

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            gela Gela Kobaidze
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes