1.下載下傳QuaZIP
http://sourceforge.net/projects/quazip/
2.編譯
linux下的編譯QuaZIP官網上有說明,這裡說下怎麼在Windows下編譯。
2.1 用Qt(版本5以上會出錯,我用的是4.8.6版本)打開D:\quazip-0.7.1\quazip項目。
2.2 右鍵qmake,然後建構
3.引用QuaZIP,下面的目錄結構是Qt官方文檔使用的方法:
在項目下建立一個檔案quazip-0.7.1,在這個檔案建立bin,include,lib
testapp
quazip-0.7.1
bin
include
lib
bin下放編譯好的quazip.dll
lib 下放quazip的lib檔案 quazip.lib(此編譯沒有生成lib檔案,是以不需要)
include下放quazip的所有頭檔案
crypt.h
ioapi.h
JlCompress.h
quaadler32.h
quachecksum32.h
quacrc32.h
quagzipfile.h
quaziodevice.h
quazip.h
quazip_global.h
quazipdir.h
quazipfile.h
quazipfileinfo.h
quazipnewinfo.h
unzip.h
zip.h
4.在項目中pro加入:
win32:CONFIG(release,debug|release):LIBS+=-L$$PWD/quazip-0.7.1/bin/-lquazip
else:win32:CONFIG(debug,debug|release):LIBS+=-L$$PWD/quazip-0.7.1/bin/-lquazip
INCLUDEPATH+=$$PWD/quazip-0.7.1/include
DEPENDPATH+=$$PWD/quazip-0.7.1/include
5.解壓縮測試
#include"quazip-0.7.1/include/JlCompress.h"
bool MainWindow::Extract(const QString& in_file_path, const QString&out_file_path)
{
QuaZip archive(in_file_path);if (!archive.open(QuaZip::mdUnzip))return false;
QString path=out_file_path;if (!path.endsWith("/") && !out_file_path.endsWith("\\"))
path+= "/";
QDir dir(out_file_path);if (!dir.exists())
dir.mkpath(out_file_path);for( bool f = archive.goToFirstFile(); f; f =archive.goToNextFile() )
{
QString filePath=archive.getCurrentFileName();
QuaZipFile zFile(archive.getZipName(), filePath);
zFile.open(QIODevice::ReadOnly );
QByteArray ba=zFile.readAll();
zFile.close();if (filePath.endsWith("/"))
{
dir.mkpath(filePath);
}else{
QFile dstFile(path+filePath);if (!dstFile.open(QIODevice::WriteOnly))return false;
dstFile.write(ba);
dstFile.close();
}
}return true;
}
原文:http://www.cnblogs.com/ike_li/p/4973541.html