|
10Qter豆
不会插入代码啊,请版主帮我修改一下。
我需要将一些二进制文件用Qt读取出来,二进制文件存储的数据格式与大小是已知的。读取时发现,qint16类型的数据读出来是实际值的256倍,int类型的读出来是实际值的16777216倍,float和double类型也是一个超级大的指数倍数关系。以Int16为例,C#创建Int16格式的二进制文件代码如下:
- public void readInt16()
- {
- string int16Path = "C:/Users/FangZhe/Desktop/test/int16_binary_generate_by_qt.bin";
- System.IO.FileStream fs = new System.IO.FileStream(int16Path, FileMode.Open, FileAccess.Read);
- BinaryReader pBinaryReader = new BinaryReader(fs);
- Console.WriteLine("int16:");
- for (int j = 0; j < 10; j++)
- {
- Int16 temp0 = pBinaryReader.ReadInt16();
- Console.WriteLine(temp0);
- }
- }
复制代码
Qt读取的代码如下:- void MainWindow::on_btnReadInt16Bin_clicked(){
复制代码
C#输入的是1到10,Qt读出的却是这样:
output = 256
output = 512
output = 768
output = 1024
output = 1280
output = 1536
output = 1792
output = 2048
output = 2304
output = 2560
经过测试发现,Qt创建,C#读取到的数值也会扩大相同的倍数。用Qt创建再用Qt读取,或者用C#创建再用C#读取是没有问题的。
测试我要用的其他软件生成的二进制数据,发现C#读取的结果是正确的。
求大佬解答。
|
|