QString.toInt() does not convert special hex numbers
-
Hello,
I tried to convert 2 hex numbers stored in a QString into a number using the toInt() method.
The first number is 0x5AC366BD which converts fine.
The second number is 0xA53C3CDB which failed to convert.
The code is the following:QString Signature1 = "0x5AC366BD";
QString Signature2 = "0xA53C3CDB";
bool ok;
qint32 sig1 = Signature1.toInt(&ok,0);
qint32 sig2 = Signature2.toInt(&ok,0);So nothing special I thought.
I use Qt 5.4.1 compiled with GCC 4.9.2 64 Bit and QtCreator 3.3.2
Does anybody have an Idea what may be the problem?
Regards
Michael -
@zerocom This is implementation defined and will return a negative qint32 on some implementations and truncated positive value on others.
The correct thing to do is to usetoLongLong
. You can then inspect the value as along long
and decide what to do with it next, depending on what you expect (a negative or positive number), and provide a correct manual conversion or truncation.