简体   繁体   English

如何转换 QVector<double> 到 QByteArray 并压缩它

[英]How to convert QVector<double> to QByteArray and compress it

I would like to convert QVector to QByteArray.我想将 QVector 转换为 QByteArray。 I am using something like this:我正在使用这样的东西:

QByteArray bytesArray
QDataStream out(&bytesArray ,QIODevice::WriteOnly);
out << someVector;
bytesArray = qCompress(bytesArray, 5);

And to read it:并阅读它:

bytesArray = qUncompress(bytesArray)
QDataStream in(bytesArray);
QVector<qreal> otherVector;
in >> otherVector;

But i have a problem.但我有一个问题。 I saved number like 1.23124121242135, and after reading i got 1.23124.我保存了像 1.23124121242135 这样的数字,阅读后我得到了 1.23124。 How can i store and read full number?如何存储和读取完整号码?

If for any reason it wont allow storing the value( eg. 0.0 +10 or more decimals u could do a workaround 1 convert double t string and get t_size to int 2 create a long or another int according to the length of said value and multiply it with the size of original and save size with the new int value.如果由于任何原因它不允许存储值(例如 0.0 +10 或更多小数你可以做一个变通方法 1 转换双 t 字符串并获得 t_size 到 int 2 根据所述值的长度创建一个 long 或另一个 int 并乘以它使用原始大小并使用新的 int 值保存大小。

If original is 1.876649018 size is 10 so the multiplier is 10^10如果原始是 1.876649018 大小是 10 所以乘数是 10^10

3 getting it back is just a matter of division of new long int value with the size 3 取回它只是将新的 long int 值与大小相除的问题

That is the only thing that comes to mind right now...这是现在唯一想到的事情......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM