Qt压缩和解压 zip

zlib编译详见
https://blog.csdn.net/zhangxuechao_/article/details/85049711

下载quazip
https://github.com/stachenov/quazip

也可直接下载我配置好的quazip
https://github.com/zwx230741/quazip.git

加入头文件
在quazip中创建include文件夹
1
将zlib头文件拷贝到include文件夹下
2
加入动态库文件
在quazip中创建lib文件夹
1
将zlib编译好的动态库拷贝到lib文件夹下
2
quazip工程配置
修改quazip.pro工程文件。添加头文件路径和动态库路径

INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/lib -lzlib1

3
编译动态库
3
不加入头文件,报以下错误
4


创建测试工程quazipTest
同理,创建include和lib目录。分别放头文件和动态库文件
5
拷贝头文件
从quazip拷贝所有头文件
2
拷贝库文件
拷贝刚刚生成的动态库文件。quazipd.dll是Debug生成的,quazipd.dll是quazipd.dll生成的,zlib1.dll是zlib动态库
3
quazipTest工程配置
修改quazipTest.pro工程文件。添加头文件路径和动态库路径

INCLUDEPATH += $$PWD/include

CONFIG(debug, debug|release) {
    LIBS += -L$$PWD/lib -lquazipd
} else {
    LIBS += -L$$PWD/lib -lquazip
}

添加压缩解压代码

#include "mainwindow.h"
#include <QApplication>
#include <JlCompress.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    JlCompress::compressDir("D:/testzip/a.zip", "D:/testzipdir1");
    JlCompress::extractDir("D:/testzip/a.zip", "D:/testzipdir2");
    
    return a.exec();
}

我测试好的工程:https://github.com/zwx230741/quazipTest.git

posted @ 2018-10-11 17:39  thomas_blog  阅读(1851)  评论(0编辑  收藏  举报