天天看点

linux下编译安装quazip,QuaZIP 使用

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