Results 1 to 5 of 5

Thread: int to String Conversion

  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default int to String Conversion

    hi...

    i'm having some doubt regarding conversion of int to string.

    Suppose

    Qt Code:
    1. int iAscii_Val =65;
    2. //As 65 in Ascii represents 'A'
    3. QString strAscii = iAscii_Val;
    To copy to clipboard, switch view to plain text mode 

    Is there any method to convert so that i can get "A" in strAscii[QString] ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: int to String Conversion

    See the docs to QChar.

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

    aj2903 (4th December 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: int to String Conversion

    @aj2903
    see this little piece of code

    Qt Code:
    1. int iAscii_Val = 65;
    2. QString strAscii = QChar(iAscii_Val).toAscii();
    To copy to clipboard, switch view to plain text mode 
    ..:: Still Standing Strong ::..

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: int to String Conversion

    What's new in your answer? But anyway, it makes no sens to convert the QChar to char before assigning it to a QString, since QString will convert it back. So this conversion is useless.

  6. #5
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: int to String Conversion

    Quote Originally Posted by Lykurg View Post
    What's new in your answer? But anyway, it makes no sens to convert the QChar to char before assigning it to a QString, since QString will convert it back. So this conversion is useless.
    You are absolutely right

    it should be:
    Qt Code:
    1. int iAscii_Val = 65;
    2. QString strAscii = QChar(iAscii_Val);
    To copy to clipboard, switch view to plain text mode 

    The reason I answered was just to be helpful for other people that are struggling with it ( and now have some cut 'n' paste code they can use )
    Last edited by BrainB0ne; 4th December 2009 at 23:01.
    ..:: Still Standing Strong ::..

Similar Threads

  1. Using ANSI string type
    By kahahn in forum Newbie
    Replies: 1
    Last Post: 20th June 2009, 23:52
  2. Replies: 0
    Last Post: 18th February 2009, 13:31
  3. Conversion Char Array to string
    By anafor2004 in forum Newbie
    Replies: 6
    Last Post: 6th May 2008, 14:35
  4. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  5. Create pixmap image from string
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2006, 16:38

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.