Results 1 to 9 of 9

Thread: How to get ASCII value of each character of a QString?

  1. #1
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default How to get ASCII value of each character of a QString?

    Hi, I m new to QT and learning it (version 4). I am trying to get ASCII of each character present in QString.

    Qt Code:
    1. int asciiVal;
    2. QString name =ui->lineEdit->text();
    3. for(int i=0; i <= name.length(); i++)
    4. {
    5. // Get ASCII VALUE into asciiVal
    6. }
    7.  
    8. // SHow into another lineEdit
    9. ui->lineEdit2->setText(asciiVal);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: How to get ASCII value of each character of a QString?

    Qt Code:
    1. asciiVal = name.at(i).toAscii();
    To copy to clipboard, switch view to plain text mode 

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

    askrina (11th April 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ASCII value of each character of a QString?

    Yes it working, Thank.

    I also found other way to do it.
    strcpy(asciiVal,name.toLatin1());
    .

  5. #4
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ASCII value of each character of a QString?

    How to get Char value of each ASCII to QString?
    Last edited by askrina; 11th April 2010 at 12:31.

  6. #5
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get ASCII value of each character of a QString?

    Just pass that value to QChar construtor.

  7. #6
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ASCII value of each character of a QString?

    Could you please show the code!

  8. #7
    Join Date
    Mar 2010
    Posts
    11
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: How to get ASCII value of each character of a QString?

    You can use this.

    Qt Code:
    1. QChar ch = string.at(i).toAscii();
    2. int chValue = ch.toAscii();
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to JackHammer for this useful post:

    askrina (14th April 2010)

  10. #8
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get ASCII value of each character of a QString?

    e.g.

    Char to ASCII
    Qt Code:
    1. // ...
    2. int ascii = c.toAscii();
    To copy to clipboard, switch view to plain text mode 

    ASCII to char
    Qt Code:
    1. int ascii;
    2. // ..
    3. QChar c(ascii);
    4. //or
    5. d.fromAscii(ascii);
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  11. The following user says thank you to lyuts for this useful post:

    askrina (14th April 2010)

  12. #9
    Join Date
    Apr 2010
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ASCII value of each character of a QString?

    thanks all you

Similar Threads

  1. ASCII to int and int to ASCII
    By askbapi in forum Newbie
    Replies: 2
    Last Post: 31st March 2010, 22:36
  2. ASCII to PDF
    By jaca in forum Newbie
    Replies: 3
    Last Post: 19th September 2009, 23:51
  3. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  4. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  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.