QString to windows BYTE
QString to windows BYTE
我有一个类型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;
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux for Windows上编译C++代码时出错
- 在Windows上用C++裁剪HBITMAP
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- Windows/Cygwin - 不能使用 pybind11 - 犯错误
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 在Windows中以.exe的形式运行c++
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 无法在windows控制台中为C++程序提供必要的输入
- 在Windows中查找扬声器输出的当前音量级别
- Windows.h与GLFW.h的接口
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 在Linux和C++中的Windows上,散列字符串值会产生不同的输出
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- 如何在Windows上将BYTE数组映射为FILE *
- QString to windows BYTE