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

Issue with QList and type of index use to get value from list

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 4.7.0, 4.7.2, 5.10.0
    • None
    • OS : Mac OS X 10.6.7
      Processor : 2 * 2.66 GHz Dual-Core Intel Xeon
      Memory : 6 GB 667 MHz DDR2 FB-DIMM
    • macOS
    • 5357231c0a10eef558cc6aebfd172048dc010a96

    Description

      This simple code give it to me strange result.

      main.cpp:

      #include <QCoreApplication>
      #include <QStringList>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          unsigned int    unsignedIndex = 1;
          QList<float>    floatList;
          QStringList     variantList;
          int j = 0;
      
          floatList << 99.4f << 85.6f;
          variantList << QString("First Object") << QString("Second Object") ;
      
          for(j = 0; j < variantList.count(); j++){
              QString testVar = variantList.at(j);
      
              if( (0 != j) && (0 != unsignedIndex))
              {
                  qDebug("Float val from int index : %.2f", floatList.at((j-1)));
                  qDebug("Float val from unsigned int index : %.2f", floatList.at(unsignedIndex - 1));
              }
      
              qDebug(testVar.toUtf8());
      
              unsignedIndex++;
          }
      
          return 0;
      }
      

      Project file (.pro):

      QT       += core
      QT       -= gui
      
      TARGET = TestCompilerIssue
      CONFIG   += console
      
      TEMPLATE = app
      CONFIG += x86
      
      SOURCES += main.cpp
      

      The result is different when I compile this example in debug and release mode.
      In debug mode I get the following correct result in the console:

      First Object
      Float val from int index : 99.40
      Float val from unsigned int index : 85.60
      Second Object

      In release mode I get the following incorrect result in the console:

      First Object
      Float val from int index : 0.00
      Float val from unsigned int index : 85.60
      Second Object

      I don't understand why I get the following result because every variables are initialised correctly.
      I suppose that it is a compiler issue but I am not sure. As you can see use an int or an unsigned int give different result.

      I use the QtCreator 2.0.1 with the default compiler GCC under Mac OS 10.6.X.
      I was not able to reproduce this issue under any Windows OS (XP, Vista, Seven).
      I was not able to check if this issue is reproductible under other Mac OS like 10.5.

      Thank you for your help.

      Attachments

        Issue Links

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

          Activity

            People

              laknoll Lars Knoll
              beni46 Thomas
              Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes