问题:QDataStream 使用"<<"方法写入数据,有多余的字符,如16进制表示为“0000 001a”
解决:QDataStream 使用writeRawData()方法写入数据能够避免多余字节的产生
QFile file(“file.txt”);
file.open(QIODevice::WriteOnly);
QDataStream out(&file); // we will serialize the data into the file
//原代码
//使用操作符输入会使out带有无效字符,输出结果为30
//out << QString(“the answer is”); // serialize a string
//更改后的代码
//输出结果为14,没有无效字符
out.writeRawData(“the answer is”,sizeof(“the answer is”));
qDebug()<<"length : "<<file.size();
file.close();
exit(1);
1633

被折叠的 条评论
为什么被折叠?



