Qt Creator 编译quazip

环境:

win10

Qt Creator 4.13.3

cmake 3.18.4

quazip 1.3

quazip下载地址:Releases · stachenov/quazip · GitHubQt/C++ wrapper over minizip. Contribute to stachenov/quazip development by creating an account on GitHub.https://github.com/stachenov/quazip/releases

文档地址:QuaZip: QuaZip - Qt/C++ wrapper for Miniziphttps://stachenov.github.io/quazip/

编译方法如下: 

使用Qt Creator打开quazip-1.3\CMakeLists.txt,会自动导入

选择kits,我选择了Qt 5.15.0 MSVC2019 32bit,然后点击configure Project,再然后就报错了

 

 错误:

CMake Error at D:/ProgramFiles/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)

官方文档有解决方法,当然也可以自己填写zlib的路径

On Windows, it may be required to use -G "MinGW Makefiles" or something like that to convince CMake that you really want to use, say, MinGW and not Visual Studio, for example.

It can be a pain to install zlib on Windows, so there's a possible workaround using zlib bundled into Qt itself. Note that this zlib is Qt's internal implementation detail, so it's more like a dirty hack, but it can be convenient. To enable this feature, configure QuaZip with

-D QUAZIP_USE_QT_ZLIB=ON

This option defaults to OFF, and even when enabled, if it fails to find zlib that comes with Qt, it will fall back to looking for a stand-alone zlib.

回到项目配置页面,添加一个Boolean型参数,QUAZIP_USE_QT_ZLIB,默认位OFF,勾选则会变为ON, 点击Apply Configuration Changes, 导入成功了

 在Qt Creator 7.0.0参数添加到Additional CMake options处

导入成功后,显示了一些可以修改的参数

 之后应该直接build就行了,然后再次失败,再次显示了Could NOT find ZLIB,

再次配置了一次QUAZIP_USE_QT_ZLIB,这次可以成功编译,原因未知

除了使用CMAKE参数,还可以直接修改CMakeLists.txt文件,修改项如下,改成ON,应该就是默认使用QT zlib

部署:

再次回到项目配置页面,Build步骤,点击详情显示更多参数,勾选install,修改CMAK_INSTALL_PREFIX, 不要设置为C盘,会因为权限问题失败,而且要配置绝对路径

应用修改

再次build,这次会自动把生成的库复制到刚才配置的路径下 

 

在使用导出的头文件和生成的lib、dll时会报错

fatal error C1083: 无法打开包括文件: “zlib.h”: No such file or directory

需要在pro中添加

INCLUDEPATH += "$$[QT_INSTALL_HEADERS]/QtZlib"

在项目pro文件添加quazip库的,quazip放在工程目录的上层目录,所以路径为$$PWD/../

# 添加quazip库信息
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../quazip-1.3lib/lib -lquazip1-qt5
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../quazip-1.3lib/lib -lquazip1-qt5d
# quazip头文件路径
INCLUDEPATH += $$PWD/../quazip-1.3lib/include/QuaZip-Qt5-1.3
# 使用Qt内置的zlib.h文件,添加到includepath,方便直接使用#include <zlib.h>,不然就修改为#include <QtZlib/zlib.h>
INCLUDEPATH += "$$[QT_INSTALL_HEADERS]/QtZlib"
# 复制quazip的dll到生成目标目录
win32:CONFIG(release, debug|release): QMAKE_PRE_LINK += xcopy /D /F /E /Y \"$${PWD}/../quazip-1.3lib/bin/quazip1-qt5.dll\" \"$${DESTDIR}\"
win32:CONFIG(debug, debug|release): QMAKE_PRE_LINK += xcopy /D /F /E /Y \"$${PWD}/../quazip-1.3lib/bin/quazip1-qt5d.dll\" \"$${DESTDIR}\"

内存压缩解压封装:

使用quazip在内存中压缩和解压_坤仔N的博客-CSDN博客

工程代码git:

https://gitee.com/chenjk10/quaziptest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值