Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946
QString.toInt() does not convert special hex numbers
mbreier last edited by
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";
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?
Dani last edited by Dani
@mbreier the second number is greater than the maximum value of qint32.
zerocom last edited by
Try toUInt(&ok,0) and convert it later to qint32.
@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 use
toLongLong. You can then inspect the value as a
long longand 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.