Results 1 to 8 of 8

Thread: int to QString with points?

  1. #1
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default int to QString with points?

    Hi all,

    how can I convert a int to QString with points between?

    Qt Code:
    1. // qint64 12282825169 = size of a directory
    2. QString str = QString::number(12282825169) + " Bytes"; // str = "12282825169 Bytes"
    To copy to clipboard, switch view to plain text mode 
    but I need:

    Qt Code:
    1. str = "12.282.825.169 Bytes"
    To copy to clipboard, switch view to plain text mode 
    How can I do this?

    Thx!
    Chris

  2. #2
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: int to QString with points?

    Well first convert to normal string and then you can use the insert function to insert points where you like and append "Bytes" at the end

  3. #3
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: int to QString with points?

    How? The string/qint64 is differently long!

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: int to QString with points?

    It requires programming. Create the string view of the number, break it apart (with mid()), insert the dots (append()).

    [Oops -- forgot about insert() -- probably the better approach. Remember to work from the tail end.]

  5. #5
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: int to QString with points?

    Quote Originally Posted by realdarkman71 View Post
    How? The string/qint64 is differently long!
    Well you have to figure the logic your self. But something like you check how long it is and then depending on that you put the dots where you want them.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: int to QString with points?

    QLOcale::toString produces a localized string representation of the given number.

  7. #7
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: int to QString with points?

    Quote Originally Posted by Lesiok View Post
    QLOcale::toString produces a localized string representation of the given number.
    This is exactly what I looked for! Thanks for your help!

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: int to QString with points?

    Your "points" are thousand or group separators. If you want the number formatted with thousands separators appropriate for the user's locale then the QLocale methods are the ones to use. Depending on where in the world you are you will get different characters in this role, most commonly a comma.

    If you actually wanted to insert periods "." into the string regardless of your locale settings, then you will need to do this yourself or force QLocale to always use a locale with "." as the group separator.

Similar Threads

  1. Replies: 8
    Last Post: 25th November 2010, 11:40
  2. Replies: 4
    Last Post: 1st February 2010, 14:21
  3. Basic Points of QT
    By BalaQT in forum Newbie
    Replies: 1
    Last Post: 14th August 2009, 06:39
  4. Plotting points
    By afflictedd2 in forum Qt Programming
    Replies: 8
    Last Post: 26th February 2009, 08:20
  5. Replies: 4
    Last Post: 31st January 2008, 20:44

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.