'QT String to short int - Hex Value
I want to convert QString to short int. For eg,
Input: QString str = "0x0001"; Output: short int num = 0x0001;
I have tried toShort() method of QString but it converts "0x0024" to 24. But I want 0x0024 as the value. I know that short int can store value in the form of 0x.
Solution 1:[1]
It makes sense to use toShort or toUInt. However when using these functions, you have to give 10 instead of 16 to get the decimal value. For eg:
short hex = str.toUInt(&ok, 16); // returns 24
short dec = str.toUInt(&ok, 10); // returns 36
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mertsert |
