当前位置:网站首页>How QT uses quazip to compress and decompress files
How QT uses quazip to compress and decompress files
2022-06-26 10:23:00 【hellokandy】
One 、QuaZIP What is it?
QuaZIP is a simple C++ wrapper over Gilles Vollant’s ZIP/UNZIP package that can be used to access ZIP archives. It uses the Qt toolkit.
- Official homepage :http://quazip.sourceforge.net/
- github Address :https://github.com/stachenov/quazip
- souceforge Download address :https://sourceforge.net/projects/quazip/
Two 、 How to compile
2.1、 Use CMake compile
The first thing to know :quazip It's right zlib Encapsulation , Need to rely on zlib Library . Use it directly CMake If you compile, you will encounter zlib Library path problem :
Have a problem :
CMake Tips :Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Solution :
be aware https://github.com/stachenov/quazip In the downloaded compressed package , There's a file NEWS.txt:
QuaZip changes
* 2021-11-13 1.2
* Add CMake option to disable installation (Sebastian Rettenberger)
* Qt's internal zlib can be used now (QUAZIP_USE_QT_ZLIB, OFF by
default)
* Make tests optional (QUAZIP_ENABLE_TESTS, OFF by default)
(Gleb Ignatev)
* Fix: QuaZip::close() can be safely called multiple times now
* Fix: -lz added to pkgconfig
among Qt’s internal zlib can be used now (QUAZIP_USE_QT_ZLIB, OFF bydefault), mean , Support direct use QT Built in zlib.
- A、 modify CMakeLists.txt Medium option(QUAZIP_USE_QT_ZLIB “” OFF), by option(QUAZIP_USE_QT_ZLIB “” ON)
- B、 Reuse CMake( belt gui Interface ) Configure as needed , After the configuration is completed, a QuaZip.sln
- C、 compile QuaZip.sln, After that, you can get quazip1-qt5.dll
2.2、 Manually create new quazip engineering
A、 download zlib, Address :http://www.zlib.net/
B、 compile zlib, direct cmake Recompile,
C、 newly build quazip Of vs engineering (qt), hold quazip The files in the compressed package are moved to the new project , And then put zlib Configure to in the form of a third-party library quazip engineering ,
- C/C++ > routine > Attach include directory :./zlib-1.2.11/include/
- C/C++ > Preprocessing > Preprocessing definition :QUAZIP_BUILD
- The linker > routine > Additional Library Directory : ./zlib-1.2.11/lib/x86/
- The linker > Input > Additional dependency :zlibd.lib
D、 compile quazip.sln engineering , Finally get quazip.dll
It should be noted that ,quazip.dll Need to rely on zlib.dll, So you need to put... Where you need it zlib.dll Take it with you , While using quazip1-qt5.dll, You don't need to .
3、 ... and 、 Sample code
#include <QtCore/QCoreApplication>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QDateTime>
#include <QDebug>
#include <QElapsedTimer>
#include <QJsonDocument>
#include <QJsonObject>
#include "JlCompress.h"
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
QString zipName = QString("%1%2").arg("./download/").arg("package.zip");
QString unzipDir = "./unzip_dir";
QDir dir(unzipDir);
if (!dir.exists())
{
bool okey = dir.mkdir(unzipDir);
//bool okey = dir.mkpath(unzipDir);
QString tip = QString("mkpath %1,%2").arg(unzipDir).arg(okey);
qDebug() << tip;
}
QElapsedTimer timer;
timer.start();
QStringList files = {
};
QFileInfo fileInfo(zipName);
if (fileInfo.exists())
{
files = JlCompress::extractDir(zipName, unzipDir);
}
qDebug() << "files count:" << files.size();
qDebug() << "the operation(JlCompress::extractDir) took" << timer.elapsed() << "ms";
QVariantMap NameAndPathMap;
// The extracted files here are sorted by file name
foreach(QString fileItem, files)
{
QString fileName = QFileInfo(fileItem).fileName();
qint64 fileSize = QFileInfo(fileItem).size();
qDebug() << "Name:" << fileName << "Size:" << fileSize << "\tPath:" << fileItem;
//
NameAndPathMap.insert(fileName, fileItem);
}
//save to file
QJsonObject root = QJsonObject::fromVariantMap(NameAndPathMap);
QString content = QString(QJsonDocument(root).toJson(QJsonDocument::Indented/*Compact*/));
//
QFile writer("./content.json");
if (writer.open(QIODevice::WriteOnly))
{
writer.write(content.toUtf8());
writer.close();
}
qDebug() << "over!!!";
return a.exec();
}
Four 、 The pit of tread
Compile the zlib after , Added to the environment variables ZLIB_LIBRARY and ZLIB_INCLUDE_DIR, But in CMake To configure quazip when , It didn't work .
As for some online use cmake Command build , I haven't tried , for example :
cmake .. -DZLIB_INCLUDE_DIR=E:\zlib\zlib-1.2.11 -DZLIB_LIBRARY=E:\zlib\zlib-1.2.11\zlibstaticd.lib
If you are interested in children's shoes and have time, you can try them .
边栏推荐
- 字符串常量池、class常量池和运行时常量池
- [depth first search] 312 Poke balloon
- Automated testing -- Introduction and example of pytest framework
- 創建對象的時候堆內存的分配
- Battery historian analyzes battery consumption
- libmagic 介绍
- Recyclerview implements flow layout (LinearLayout with line wrap) (flexboxlayoutmanager)
- Servlet learning notes II
- How to change the QR code material color of wechat applet
- MySQL第十一作业-视图的应用
猜你喜欢

What should the preview do?

全渠道、多场景、跨平台,App如何借助数据分析渠道流量

The fourteenth MySQL operation - e-mall project

Call API interface to generate QR code of wechat applet with different colors

Establishment of smart dialogue platform for wechat official account

MySQL 13th job - transaction management

首批12家企业入驻!广州首个集中展销老字号产品专柜开张

Little red book - Notes inspiration - project summary

如何更改微信小程序二维码物料颜色

Extracting public fragments from thymeleaf
随机推荐
The first batch of 12 enterprises settled in! Opening of the first time-honored product counter in Guangzhou
Leetcode intermediate node of linked list
MySQL第五章总结
What is a botnet
MySQL第十一作業-視圖的應用
Allocation of heap memory when creating objects
Using foreach to loop two-dimensional array
Yarn package management tool
【Leetcode】76. Minimum covering substring
Battery historian analyzes battery consumption
Appium自动化测试基础 — 移动端测试环境搭建(二)
微软 Edge 浏览器 IE 模式标签页出现卡死情况,已通过回滚更新修复
DBSCAN
全渠道、多场景、跨平台,App如何借助数据分析渠道流量
Automated testing -- on the coexistence of Unitest and pytest initialization
创建对象的时候堆内存的分配
mysql学习总结
字符串常量池、class常量池和运行时常量池
MySQL第十四次作业--电子商城项目
动态库连接 - 符号冲突 - 全局符号介入