Use Quazip in Qt to compress and decompress files

Source: Internet
Author: User
Tags zip


1. Introduction


The Quazip is an open-source library for compressing zip and extracting zip using the qt,c++ zlib for simple encapsulation. If you use compression and unzip zip in your QT project, you might consider using it.



Official homepage: http://quazip.sourceforge.net/



Souceforge Download Address: http://sourceforge.net/projects/quazip/



2. Compiling


Quazip is based on the Zlib library, before compiling to import zlib header file, compiled will generate Quazip.lib and Quazip.dll files (with VS)



If using QT to compile, the direct compilation will be error, need to add zlib.h containing directory, in the Quazip/quazip.pro file add Includepath + = "qt Source directory \src\qtbase\src\3rdparty\zlib"



Subdirs = Quazip qztest comments in the Quazip.pro file are also replaced with subdirs = Quazip, and selecting rebuild will generate LIBQUAZIPD.A and Quazipd.dll



3. Application


Add the directory where the Quazip.lib is located in your new project to the project.



Compress and decompress files with the Jlcompress class in Quazip



static method Compressed File



static bool Compressdir (QString filecompressed, QString dir=qstring (), bool recursive = TRUE)



The first parameter, filecompressed, represents a compressed file



The second parameter, dir, indicates the directory to be compressed



The third parameter, recursive, indicates whether recursion



static method for decompression: Extractdir



Static Qstringlist Extractdir (QString filecompressed, QString dir=qstring ())



The first parameter, filecompressed, represents the file to be decompressed



The second parameter represents the directory where the decompression resides



Here is an example of the program code:





#include <QCoreApplication>
#include "JlCompress.h"



int main (int argc, char *argv[])
{
    Qcoreapplication A (argc, argv);

    Jlcompress::compressdir ("D:\\test.zip", "d:\\test"); Compress
    jlcompress::extractdir ("D:\\test.zip", "d:\\test");//Unzip
    return a.exec ();
}













Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.