QT编译quazip库

什么是quazip

QuaZIP是使用Qt/C++对ZLIB进行简单封装的用于压缩及解压缩ZIP的开源库。适用于多种平台,利用它可以很方便的将单个或多个文件打包为zip文件,且打包后的zip文件可以通过其它工具打开。但是使用QT编译此库,需要依赖zlib库,现在从用cmake编译zib库开始,详细讲述编译过程,最终得到我们想要的quazip库。

下载源码

  1. zlib官网戳这里;下载最新版本源码,我的版本是1.2.11
  2. quazip官网戳这里;下载最新版本源码,我的版本是0.7.3

使用cmake构建zlib库

需要将QT安装目录下Tools\mingw730_64\bin\mingw32-make.exe添加至系统环境变量,本文章以64位为例,32位操作与64位同理。
由于没有将mingw32-make.exe添加至系统环境变量,我直接使用另一种方法(懒得重启电脑)打开cmake,效果相同。

  1. 使用Qt5.14.1(MinGW7.3.0 64-bit) 进入到cmake安装目录下,输入cmake-gui.exe回车后打开cmake-gui,这中打开方式不推荐(若已经添加环境变量mingw32-make.exe,直接打开cmake-gui即可)。
    在这里插入图片描述
  2. 点击Configure,选择MinGw Makefiles和指定编译器,点击Next
    在这里插入图片描述
  3. C中选择QT/Tools/mingw730_64/bin/gcc.exe,C++ 中选择QT/Tools/mingw730_64/bin/g++.exe,点击Finish开始Configure,界面中输出Configureing done表示完成 (32位请使用QT/Tools/mingw730_32/目录)
    在这里插入图片描述
    在这里插入图片描述
  4. 点击Generate生成makefile文件,界面输出Generating done表示生成结束
    在这里插入图片描述

使用Qt编译zlib库

  1. 打开Qt 5.14.1(MinGW 7.3.0 64-bit) 进入刚才的 buid文件夹中,执行mingw32-make.exe,等待编译完成,可以在目录下看到生成的动态库和静态库文件 (因我已经生成过,所以编译输出信息不全)
    在这里插入图片描述
  2. 若需要编译32的zlib库,请使用Qt 5.14.1(MinGW 7.3.0 32-bit) 进行上一步的操作。编译完成后整理好源码中的头文件和编译生成的库文件,供编译quazip使用,接下来开始编译quazip

使用Qt编译quazip库

  1. 使用Qtcreator打开下载好的quazip0.7.3源码pro工程文件,在pro文件中注释qztest模块
    在这里插入图片描述
  2. 在第二级pro工程文件中添加外部库,导入刚编译整理好的zlib库文件和头文件 (这里使用的是32位zlib库),注意构想项目选用 32位 编译器,64位同理
    在这里插入图片描述
  3. 执行qmake后,构建整个项目,等待编译结束后,可以在文件中看到生成的动态库文件
    在这里插入图片描述
  4. 整理好quazip的头文件库文件,至此已经编译出可以使用的quazip动态库
    (PS:因编译quazip时引入的是zlib的动态库,所以真正使用时需要将quazip.dll和libzlib.dll都拷到项目运行目录下,若编译quazip引入的是zlib的静态库,则使用时只需要quazip.dll一个文件即可)

使用方法

引入JlCompress.h头文件

**压缩方法**
/// Compress a single file.
    /**
      \param fileCompressed The name of the archive.
      \param file The file to compress.
      \return true if success, false otherwise.
      */
    static bool compressFile(QString fileCompressed, QString file);
    /// Compress a list of files.
    /**
      \param fileCompressed The name of the archive.
      \param files The file list to compress.
      \return true if success, false otherwise.
      */
    static bool compressFiles(QString fileCompressed, QStringList files);
    /// Compress a whole directory.
    /**
      Does not compress hidden files. See compressDir(QString, QString, bool, QDir::Filters).

      \param fileCompressed The name of the archive.
      \param dir The directory to compress.
      \param recursive Whether to pack the subdirectories as well, or
      just regular files.
      \return true if success, false otherwise.
      */
    static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true);
    /**
     * @brief Compress a whole directory.
     *
     * Unless filters are specified explicitly, packs
     * only regular non-hidden files (and subdirs, if @c recursive is true).
     * If filters are specified, they are OR-combined with
     * <tt>%QDir::AllDirs|%QDir::NoDotAndDotDot</tt> when searching for dirs
     * and with <tt>QDir::Files</tt> when searching for files.
     *
     * @param fileCompressed path to the resulting archive
     * @param dir path to the directory being compressed
     * @param recursive if true, then the subdirectories are packed as well
     * @param filters what to pack, filters are applied both when searching
     * for subdirs (if packing recursively) and when looking for files to pack
     * @return true on success, false otherwise
     */
    static bool compressDir(QString fileCompressed, QString dir,
                            bool recursive, QDir::Filters filters);
**解压方法** 
/// Extract a single file.
    /**
      \param fileCompressed The name of the archive.
      \param fileName The file to extract.
      \param fileDest The destination file, assumed to be identical to
      \a file if left empty.
      \return The list of the full paths of the files extracted, empty on failure.
      */
    static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString());
    /// Extract a list of files.
    /**
      \param fileCompressed The name of the archive.
      \param files The file list to extract.
      \param dir The directory to put the files to, the current
      directory if left empty.
      \return The list of the full paths of the files extracted, empty on failure.
      */
    static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString());
    /// Extract a whole archive.
    /**
      \param fileCompressed The name of the archive.
      \param dir The directory to extract to, the current directory if
      left empty.
      \return The list of the full paths of the files extracted, empty on failure.
      */
    static QStringList extractDir(QString fileCompressed, QString dir = QString());  

具体需要哪种方法调用那种方法即可,一般会自己封装一下再使用!至此,quazip库从编译到使用完整流程STOP!!!
可以直接下载我已经编译好的32/64位quazip库和zlib库使用!戳这里
没有积分的评论区留下邮箱,看见后发你!!!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
VS2013是微软开发的一款集成开发环境,用于开发各类应用程序。在VS2013中编译QuaZIP这个时,需要按照以下步骤进行操作: 1. 下载QuaZIP源码:可以在GitHub等代码托管平台上找到QuaZIP的源码,下载并解压到本地。 2. 打开VS2013:双击打开VS2013,创建一个新的空项目。 3. 添加源码文件:在VS2013的解决方案资源管理器中,右键点击源文件夹,选择"添加"->"现有项",将QuaZIP源码目录下的所有源码文件添加到项目中。 4. 设置项目属性:右键点击项目名称,选择"属性",进入项目属性窗口。 5. 配置项目属性: 5.1 配置"VC++目录":在项目属性窗口中,选择"配置属性"->"VC++目录",添加QuaZIP源码中的include目录路径,以及QuaZIP依赖的lib目录路径。 5.2 配置"链接器":同样在项目属性窗口中,选择"配置属性"->"链接器"->"常规",添加QuaZIP依赖的lib文件路径。 5.3 配置"编译器":在项目属性窗口中,选择"配置属性"->"C/C++"->"预处理器",添加宏定义。如果需要使用Qt,还需在"常规"->"附加包含目录"中添加Qt的include目录路径。 6. 编译项目:按下F7或选择"生成"->"生成解决方案",开始编译QuaZIP。 7. 检查编译结果:在输出窗口中查看编译结果,确保没有错误和警告。 如果一切正常,编译成功后将生成QuaZIP的静态(.lib文件)和动态(.dll文件),可以在编写应用程序时调用QuaZIP的功能。 注意:以上步骤仅适用于在VS2013中编译QuaZIP,具体操作可能因环境和版本不同而有所差异。在进行编译前,建议先阅读QuaZIP的官方文档,了解的相关配置和依赖。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值