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

QString arg( int, width, base, fill ) does not work if width != 0.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.7.0
    • Fix Version/s: None
    • Labels:
    • Environment:
      QTCreator 4.0.2
      QT 5.7.0
      gcc-4.9.1
      Debian

      Description

      I was trying to create zero-filled hex strings (like sprintf( buf, "%02X", 123 )) and discovered that QString.arg(...) with a non-zero width and base 16 acts like sprintf( buf, "%.32f", 123 ):

      Sample code:

      QString ok = QString( "%1" ).arg( 123, 0, 16 );
      QString ng = QString( "%1" ).arg( 123, 2, 16, '0' );

      cerr << ok.toStdString( ) << endl;
      cerr << ng.toStdString( ) << endl;

      Sample output:

      7b
      123.000000000000000000000000000000000000000000000000

        Attachments

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

          Activity

            People

            • Assignee:
              laknoll Lars Knoll
              Reporter:
              spacewrench Dave
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes