PDA

View Full Version : converting qstring to unsigned char



havij000
22nd July 2013, 06:57
Hello every body,

I am new to Qt and need to convert a qstring variable which is a Hex number to an unsinged char array type as you can see bellow



QString str = "1234"; // which is the 0x1234 number


and I need to store it in one of the below data structure fields which is 2 byte (for instance the "unsigned char Base_Addrs[2]" field) :



struct wrt_rqst_
{
unsigned char Dest_MAC[6];
unsigned char Src_MAC[6];
unsigned char Eth_Length[2];//should be 0x0800
unsigned char Wrt_Cmd[2];//should be 0x0000
unsigned char Base_Addrs[2];
unsigned char Data_Length[2];//should be 0x02EB
unsigned char data[1494];//should be set all az 0

}*wrt_buff;



how should I convert the qstring to unsigned char? :confused:

Thanks.

wysota
22nd July 2013, 07:36
int val = str.toInt(0, 16);