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.
Code:
int asciiVal;
QString name
=ui
->lineEdit
->text
();
for(int i=0; i <= name.length(); i++)
{
// Get ASCII VALUE into asciiVal
}
// SHow into another lineEdit
ui->lineEdit2->setText(asciiVal);
Re: How to get ASCII value of each character of a QString?
Code:
asciiVal = name.at(i).toAscii();
Re: How to get ASCII value of each character of a QString?
Yes it working, Thank.
I also found other way to do it.
Quote:
strcpy(asciiVal,name.toLatin1());
.
Re: How to get ASCII value of each character of a QString?
How to get Char value of each ASCII to QString?
Re: How to get ASCII value of each character of a QString?
Just pass that value to QChar construtor.
Re: How to get ASCII value of each character of a QString?
Could you please show the code!
Re: How to get ASCII value of each character of a QString?
You can use this.
Code:
QChar ch
= string.
at(i
).
toAscii();
int chValue = ch.toAscii();
Re: How to get ASCII value of each character of a QString?
e.g.
Char to ASCII
Code:
// ...
int ascii = c.toAscii();
ASCII to char
Code:
int ascii;
// ..
//or
d.fromAscii(ascii);
Re: How to get ASCII value of each character of a QString?