PDA

View Full Version : how to retrieve ascii code of a character in a qstring?



gisac
26th May 2015, 13:28
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

anda_skoa
26th May 2015, 13:44
If you want an intepretation as an unsigned number, use an unsigned type.

Cheers,
_

gisac
26th May 2015, 19:22
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

Lesiok
26th May 2015, 20:57
dummy=(unsigned char)risposta.at(ind).toLatin1();

gisac
26th May 2015, 21:02
Just made! It's the same thing, dummy=-51 also with (unsigned char)!

gisac
26th May 2015, 23:07
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!

Lesiok
27th May 2015, 09:56
You know that these are the basics of C / C ++? It has nothing to do with Qt.

kaufenpreis
28th May 2015, 14:40
Try this:

string s = "hallo world";
foreach( char c in s)
{
Console.WriteLine(System.Convert.ToInt32(c));
}
Console.ReadLine();

d_stranz
28th May 2015, 21:40
And just what does Java code have to do with either C++ or Qt?