Results 1 to 3 of 3

Thread: QString:: Padding Zeros?

  1. #1
    Join Date
    Nov 2006
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QString:: Padding Zeros?

    Want to take an interger and produce a zero padded string output.
    Can this be done in Qt?

    e.g.
    int i = 5;
    QString str = ( code ... );
    qDebug() << str; // prints 0005


    Cheers

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QString:: Padding Zeros?

    Try with QString::arg(). You may pass a custom field width and a filling character.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Harvey West (27th February 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: QString:: Padding Zeros?

    Try QString::leftJustified or QString::rightJustified. This should work for you.

Similar Threads

  1. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 20:10
  2. Replies: 2
    Last Post: 12th October 2006, 10:17
  3. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 09:55
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 23:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 21:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.