Qt用QuaZip实现压缩/解压的小Demo

效果图:

关键代码:

 

#include "squazip.h"
#include "../quazip/JlCompress.h"
#include <QtConcurrent/QtConcurrent>

SQuaZip::SQuaZip(QObject *parent) : QObject(parent)
{
}

void SQuaZip::saveAsFile(const QString &path, const QString &zipfile)
{
    QtConcurrent::run(this, &SQuaZip::zipDir, path, zipfile);
}

void SQuaZip::loadFromFile(const QString &path, const QString &zipfile)
{
    QtConcurrent::run(this, &SQuaZip::unzipDir, zipfile, path);
}

/**
 * @brief SQuaZip::zipDir
 * @param path 待压缩目录
 * @param zipfile 压缩后的文件
 * @return
 */
bool SQuaZip::zipDir(const QString &path, const QString &zipfile)
{
    bool bok = JlCompress::compressDir(zipfile, path, true);
    return bok;
}

/**
 * @brief SQuaZip::unzipDir
 * @param zipfile 待解压缩的文件
 * @param path 解压缩存放的目录
 * @return
 */
bool SQuaZip::unzipDir(const QString &zipfile, const QString &path)
{
    bool bok = !JlCompress::extractDir(zipfile, path).isEmpty();
    qDebug() << "??::" << bok;
    return bok;
}

 

码云源码分享:

https://gitee.com/ShaShiDiZhuanLan/Demo_QuaZip

Github源码分享:

https://github.com/ShaShiDiZhuanLan/Demo_QuaZip_Qt

©️2020 CSDN 皮肤主题: 代码科技 设计师:Amelia_0503 返回首页