Results 1 to 3 of 3

Thread: int to QString with defined size

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default int to QString with defined size

    Hi,

    I'm not able to find the corresponding method of solving this.
    I have a int value and I want to get a QString with the format "XXXX", so when the value is 5 I need to get "0005".

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: int to QString with defined size

    Have a look at QString::arg() variant taking fieldWidth and fillChar parameters.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    ^NyAw^ (9th February 2012)

  4. #3
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: int to QString with defined size

    Hi,
    Thank to wysota.
    THis is example how to convert int to QString with defined size

    Qt Code:
    1. int i;
    2. QString str;
    3. i = 5;
    4. str = QString("%1").arg(i, 5, 10, QChar(48));
    To copy to clipboard, switch view to plain text mode 

    Thank you

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2011, 15:42
  2. Comparing a Qstring with a value defined in an enum
    By AndresBarbaRoja in forum Newbie
    Replies: 5
    Last Post: 24th March 2011, 16:11
  3. Replies: 4
    Last Post: 31st January 2008, 20:44
  4. QString size
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2008, 05:04
  5. window sizes changing even though max size defined
    By JonathanForQT4 in forum Newbie
    Replies: 3
    Last Post: 6th August 2007, 10:39

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.