PDA

View Full Version : Convert QString to unsigned char



taraj
13th September 2016, 00:44
Hi,

I'm sure this is really easy but I just can't work out how to do it

I have a QString which I need to put into


unsigned char tod;

Please note that tod is not a pointer (that seems easy to do). I have old-style-cast on so can't cast as (unsigned char). Using Qt5

Thanks in advance!

anda_skoa
13th September 2016, 09:07
Usually an 8 bit character implies some 8 bit encodin, e.g. UTF-8 or Latin1.

Use the respective encoding function and take the first byte of the resulting QByteArray, e.g.


string.toUtf8()[0];


Cheers,
_