Important: Please read the Qt Code of Conduct -

How to manage zip file

  • Hi. I have to manage a zip file (not gzip, just zip). Can somenone suggest me a way to do it (on both Linux and Windows)? qCompress and qUncompress does not work.


  • Lifetime Qt Champion

  • The only answer is zlib, you just need to decide the flavour

    • QuaZIP (handles only .zip, wrapper around zlib)
    • KArchive (supports multiple compression formats, for zip it's a wrapper on zlib)
    • zlib if you don't mind C then you can use directly the reference library for zip files

    I personally use KArchive because it's already conveniently wrapped in a Qt style and it can rely on the support of KDE

  • Hi. I'm trying to use quazip.
    I have built quazip package without problem. When I try to run

    JlCompress::extractDir("", ".");

    the probgram goes to crash.


    windows {
        INCLUDEPATH += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2
        INCLUDEPATH += C:/Users/Denis/git/ControlloAccessi/zlib128-dll/include
        LIBS += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release/quazip.lib


    #include "quazip/quazip.h"
    #include "QFile"
    #include "QDebug"
    #include <quazip/JlCompress.h>
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
        JlCompress::extractDir("", "b");

  • Lifetime Qt Champion

    @mrdebug Did you try to debug to see what happens? Is it SIGSEGV or something else? Any error messages?

  • @mrdebug said in How to manage zip file:

    When I try to run

    You are linking to the release version of quazip so make sure you run the release version of your app.

    change LIBS += C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release/quazip.lib into

    CONFIG(debug, debug|release) {
        LIBS += -L"C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/debug"
        LIBS += -lquazipd
    }else {
        LIBS += -L"C:/Users/Denis/git/ControlloAccessi/quazip-0.7.2/quazip/release"
        LIBS += -lquazip

    Also make sure you make both Quazip.dll and zlib.dll (if you did not compile it as static) available at runtime

  • Sorry. I have missed the required dlls.
    Is there a way to unzip a zip stream, from a QByteArray without to store it to a file before?

  • yes with
    create a QDataStream operating on the QByteArary and then pass QDataStream::device() to that constructor.

    On the other hand, I'm not sure what you are trying to do but you might not need QuaZip at all, have a look at and below

  • Someting like this?

                        QDataStream BufferIn(&Source, QIODevice::ReadOnly);
                        QuaZipFile quaZip(BufferIn.device());
                        qDebug() <<;

    returns false...

  • QuaZipFile represents a file inside a zip file, not a zip file in itself. the constructor you are calling is this one: use QuaZip instead.

    QDataStream BufferIn(&Source, QIODevice::ReadOnly); is the same as QDataStream BufferIn(Source);

  • After many tries I can't unzip something without to use a file.
    These lines of code

                            QDataStream BufferIn(&QBABufferOut, QIODevice::ReadOnly);
                            QuaZip quaZip(BufferIn.device());

    does not seem to work.

  • Lifetime Qt Champion


    What do you have in QBABufferOut ?
    Are you sure it's opened correctly ?
    Why do you need BufferIn for ?

    And most important, what do you mean by does not seem to work? That's to vague to help you.

  • Please have a look at this sequence:

                                QuaZipFile quaZip(QBABufferOut);                // (rapresents a zip archivie in ram).
                                if ( {         // QIODevice::ReadOnly or someting else
                                    qDebug() << "ok";
                                } else qDebug() << "error";                     // always error!!!!!!!!!!!!

  • You have to open the QuaZip for decompression first:

        QBuffer storageBuff(&QBABufferOut);
        QuaZip zip(&storageBuff);
        if (!
            qDebug() << "error";
        QuaZipFile file(&zip);
        for (bool f = zip.goToFirstFile(); f; f = zip.goToNextFile()) {
            QuaZipFileInfo fileInfo;
            qDebug() <<;
            qDebug() << "Content: " << file.readAll().toBase64();


    // (rapresents a zip archivie in ram).

    No it doesn't. As mentioned before QuaZipFile represent a file inside a zip archive, not the archive itself

  • It works perfectly.
    Many thanks.

Log in to reply