Results 1 to 4 of 4

Thread: Pass a float value to a string

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default Pass a float value to a string

    I need to pass the float value of an objects property to a string, which is another property of that same object, so that it can be printed in by the painter.

    The thing is, I have no idea how to either:

    a)Convert a float to a string.
    b)Pass a float as a parameter to a string.

    I tried googling first but, surprisingly, no useful answers have shown up. (Maybe I'm searching with the wrong keywords).

    Can I get any insight into this? Thanks in advance.

  2. #2
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    10
    Thanked 13 Times in 12 Posts

    Default Re: Pass a float value to a string

    Qt Code:
    1. float val = 12.0;
    2. QString str = QString::number(val);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Pass a float value to a string

    You can also use QString::arg.

  4. #4
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo
    Thanked 17 Times in 17 Posts

    Default Re: Pass a float value to a string

    Just share. QVariant is also usefull for convertions, but in this case it's better to use QString::number() or QString::arg().
    ~ We are nothing in this universe ~

Similar Threads

  1. Replies: 13
    Last Post: 30th November 2010, 13:47
  2. Replies: 2
    Last Post: 10th December 2009, 21:51
  3. Replies: 4
    Last Post: 21st June 2009, 19:06
  4. Replies: 1
    Last Post: 10th February 2009, 10:42
  5. float
    By mickey in forum General Programming
    Replies: 5
    Last Post: 25th July 2006, 12:52

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
  •  
Qt is a trademark of The Qt Company.