how to retrieve ascii code of a character in a qstring?
I'm trying to write an application with Qt 5.4, and I have to encode a string in code 128 barcode.
So, the first character in the original string is byte 205 (Ã):
dummy is an int, risposta is the QString to encode
dummy = (char) risposta.at(ind).toLatin1();
dummy, in debug mode, becomes -51, and so, it makes me break following
if (dummy < 127)
dummy -= 32;
else
dummy -= 100;
Anyone can help me?
Gisac
Re: how to retrieve ascii code of a character in a qstring?
If you want an intepretation as an unsigned number, use an unsigned type.
Cheers,
_
Re: how to retrieve ascii code of a character in a qstring?
Unfortunately, if I declare
uint dummy;
and make:
dummy=(char)risposta.at(ind).toLatin1();
or
dummy=(uint)risposta.at(ind).toLatin1();
dummy becomes 4294967245!
Help me, please!
Thanks
Re: how to retrieve ascii code of a character in a qstring?
Code:
dummy=(unsigned char)risposta.at(ind).toLatin1();
Re: how to retrieve ascii code of a character in a qstring?
Just made! It's the same thing, dummy=-51 also with (unsigned char)!
Re: how to retrieve ascii code of a character in a qstring?
Quote:
Originally Posted by
gisac
Just made! It's the same thing, dummy=-51 also with (unsigned char)!
Actually, there is a strange behavior of qcreator: in the variable window, dummy continues to have the value -51, but in the following if it is considered to have value 205.
Problem solved! thanks to all!
Re: how to retrieve ascii code of a character in a qstring?
You know that these are the basics of C / C ++? It has nothing to do with Qt.
Re: how to retrieve ascii code of a character in a qstring?
Try this:
string s = "hallo world";
foreach( char c in s)
{
Console.WriteLine(System.Convert.ToInt32(c));
}
Console.ReadLine();
Re: how to retrieve ascii code of a character in a qstring?
And just what does Java code have to do with either C++ or Qt?