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

QString::number with negative qint64 produces positive, out-of-range numbers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.13.2
    • None
    • Windows 10, CLion and/or QtCreator, x86 build, amd64 build
    • Windows

      The conversion of QString hex value to signed int 64 fails.

       

      A possible workaround may be doing the conversion using toULongLong and afterwards cast to qint64.

       

      void testToLongLong(qint64 value) {
          QString hexStrValue = QString::number(value, 16);
      
          bool ok;
          qint64 intValue;
          intValue = (qint64) hexStrValue.toULongLong(&ok, 16);
      
          Q_ASSERT_X(ok, "testToLongLong using cast", "returned not ok");
          Q_ASSERT_X(intValue == value, "testToLongLong using cast", "values differ");
      
          intValue = hexStrValue.toLongLong(&ok, 16);
      
          Q_ASSERT_X(ok, "testToLongLong using toLongLong", "returned not ok");
          Q_ASSERT_X(intValue == value, "testToLongLong using toLongLong", "values differ");
      }
      
      void testToLongLong() {
          testToLongLong(0x7FFFFFFFFFFFFFFF); // is working
          testToLongLong(0x8000000000000000); // doesn't work
          testToLongLong(0xAAAAAAAAAAAAAAAA); // doesn't work too
      }
      

        1. image-2020-01-17-18-18-40-295.png
          image-2020-01-17-18-18-40-295.png
          358 kB
        2. int64_values.PNG
          int64_values.PNG
          6 kB
        3. minus_one_hxd.PNG
          minus_one_hxd.PNG
          30 kB
        4. int64_values.PNG
          int64_values.PNG
          9 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            thiago Thiago Macieira
            m_feustel Mike Feustel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes