我正在使用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