我正在使用qUncompress的Qt和头问题,我无法找到更多的信息来解决它。 这里是我的代码:qUncompress:Z_DATA_ERROR:输入数据已损坏
#include <QCoreApplication>
#include <QByteArray>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile f("/user/XXXXX/home/AgeRegression"); // hided
if (f.exists())
qDebug() << "File exists";
else
qDebug() << "Missing file";
f.open(QIODevice::ReadOnly);
QByteArray qb = f.readAll();
qb = qUncompress(qb);
qDebug()<<"Successfully";
const char *qt_version = qVersion();
qDebug()<< QString(qt_version);
return a.exec();
}
这里是输出:
File exists
qUncompress: Z_DATA_ERROR: Input data is corrupted
Successfully
"5.3.2"
出自QT的文件(你可以找到here):
Note: If you want to use this function to uncompress external data that was compressed using zlib, you first need to prepend a four byte header to the byte array containing the data. The header must contain the expected length (in bytes) of the uncompressed data, expressed as an unsigned, big-endian, 32-bit integer.
那么究竟应该怎么办这里?我是否必须找到未压缩数据的长度(有没有办法?我只是有压缩数据。)?一个例子,将不胜感激。
我知道这可能是危险的,你的方式当然更安全。但是这个代码只是用来测试我在测试一个库时遇到的问题。谢谢。 :) – nguyeh