我想操作存储在 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)有效,但我不明白为什么我上面的代码没有给出相同的结果。
此致!