【发布时间】:2014-06-15 06:49:13
【问题描述】:
我想操作一个存储在 QByteArray 中的 32 位写入命令。但让我感到困惑的是我的 QByteArray 改变了大小,我无法弄清楚为什么会发生这种情况。
我的代码:
const char CMREFCTL[] = {0x85,0x00,0x00,0x0B};
QByteArray test = QByteArray::fromRawData(CMREFCTL, sizeof(CMREFCTL));
qDebug()<<test.toHex();
const char last1 = 0x0B;
const char last2 = 0x0A;
test.replace(3,1,&last2);
qDebug()<<test.toHex();
test.replace(3,1,&last1);
qDebug()<<test.toHex();
生成:
"0x8500000b"
"0x8500000a0ba86789"
"0x8500000ba867890ba86789"
我希望得到以下输出:
"0x8500000b"
"0x8500000a"
"0x8500000b"
使用 test.replace(3,1,&last2,1) 有效,但我不明白为什么上面的代码没有给出相同的结果。
最好的问候!
【问题讨论】:
标签: c++ qt qbytearray