0
点赞
收藏
分享

微信扫一扫

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


效果图:

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;
}

 


举报

相关推荐

0 条评论