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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.7.0
    • 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

            laknoll Lars Knoll
            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