我有一个类型BYTE,它在windows.h标头中定义如下:
typedef unsigned char BYTE;
然后我在数据库中有一些字段,我将其作为QString并将它们转换为QByteArray。
目前我有:
QString str = "0x168de78"; //some info from the database
QByteArray tempB = QByteArray::fromHex(str.toAscii().toHex());
BYTE *sequence = (BYTE*)strdup(tempB.data());
在这种情况下,"0x168de78"代表我期望从数据库中获取的信息样本。
我需要将 QString 逐字转换为 BYTE,以便以后可以使用它。
如果我告诉应用程序给我 sequence 和 tempB.data() 的值,我会得到类似于以下内容的内容:
0x867dc8 "0x168de78"
0x867de0 "0x168de78"
0x867df8 "0x168de78"
所以tempB.data()没问题,但序列不是。我做错了什么?
QString str = "0x168de78"; //some info from the database
QByteArray tempB = QByteArray::fromHex(str.toAscii());//or
//QByteArray tempB = str.toAscii().toHex();
BYTE *sequence = (BYTE*)strdup(tempB.data());
更新:如果您可以使用 STL
unsigned int value;
std::stringstream ss;
ss << std::hex << "0x168de78";
ss >> x;