I am reading the registers of the i2c device, and the range of the return value is from 32768 to 32768, signed integers. The following is an example:
0xfec7
In Qt, I get this value (0xfec7) and want to display it in QLabel as a signed integer. The variable stringListSplit [0] is a QString with the value "0xfec7".
int milAmps = stringListSplit[0].toInt(0,16);
qDebug() << milAmps;
The problem no matter what I try, I always get unsigned integers, so for this example I get 65223, which exceeds the specified maximum return value. I need to convert a hexadecimal value to a signed integer, so I need to treat the hexadecimal value as expressed with 2s padding. I do not see a simple method in the QString documentation. How can I achieve this in Qt?
NOTE:
QString:: toShort 0:
short milAmps = stringListSplit[0].toShort(0,16);
qDebug() << "My new result: " << milAmps;
stringListSplit [0], '0xfebe', -322, C-style casting, Keith :
int milAmps = stringListSplit[0].toInt(0,16);
qDebug() << "My new result: " << (int16_t)milAmps;