Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';无法打开压缩文件_C++_Qt_Zip - Fatal编程技术网

C++ Can';无法打开压缩文件

C++ Can';无法打开压缩文件,c++,qt,zip,C++,Qt,Zip,我正在尝试使用QT压缩文本文件: QFile inFile("d:\\build\\Directories\\Debug\\files\\developer.txt"); bool open_file_result = inFile.open(QIODevice::ReadOnly); QByteArray ba = inFile.readAll(); QFile file("d:\\build\\Directories\\Debug\\files\\developer.gz"); bool

我正在尝试使用QT压缩文本文件:

QFile inFile("d:\\build\\Directories\\Debug\\files\\developer.txt");
bool open_file_result = inFile.open(QIODevice::ReadOnly);
QByteArray ba = inFile.readAll();

QFile file("d:\\build\\Directories\\Debug\\files\\developer.gz");
bool open_zip_result = file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << qCompress(ba);

file.close();
QFile-infle(“d:\\build\\Directories\\Debug\\files\\developer.txt”);
bool open_file_result=infle.open(QIODevice::ReadOnly);
QByteArray ba=infle.readAll();
QFile文件(“d:\\build\\Directories\\Debug\\files\\developer.gz”);
bool open_zip_result=file.open(QIODevice::WriteOnly);
QDataStream out(文件(&F);

out压缩算法和压缩容器之间存在差异。你把这两个搞混了

您需要对Zip容器格式进行一些研究,以帮助您在Zip容器中定位和提取压缩文件。一旦获得该文件,就只能对该文件应用qUncompress


尝试查看,这是一个为此目的而编写的库。

我对
QFile
不太了解,但我知道Windows需要您以
binary
模式打开这些东西。有没有办法用
QFile
做到这一点?可能
qCompress
只压缩指定的数据,而不写gz文件头。你应该打开任何一个gz文件,检查它的头文件中是否有一些
magic
数据。和你的比较。