Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to manage zip file
QtWS25 Last Chance

How to manage zip file

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 7 Posters 31.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrdebug
    wrote on 15 Dec 2016, 07:23 last edited by VRonin 1 Oct 2017, 09:59
    #1

    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.

    Regards.

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    J 1 Reply Last reply 15 Dec 2016, 07:31
    0
    • M mrdebug
      15 Dec 2016, 07:23

      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.

      Regards.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 15 Dec 2016, 07:31 last edited by
      #2

      @mrdebug http://www.antonioborondo.com/2014/10/22/zipping-and-unzipping-files-with-qt/

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 15 Dec 2016, 07:49 last edited by VRonin 8 Feb 2018, 09:56
        #3

        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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        S 1 Reply Last reply 27 Sept 2021, 23:51
        2
        • M Offline
          M Offline
          mrdebug
          wrote on 15 Dec 2016, 08:56 last edited by VRonin
          #4

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

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

          the probgram goes to crash.

          .pro

          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
          }
          

          main.cpp

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

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          J V 2 Replies Last reply 15 Dec 2016, 09:09
          0
          • M mrdebug
            15 Dec 2016, 08:56

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

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

            the probgram goes to crash.

            .pro

            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
            }
            

            main.cpp

            #include "quazip/quazip.h"
            #include "QFile"
            #include "QDebug"
            
            #include <quazip/JlCompress.h>
            
            MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
                ui->setupUi(this);
                JlCompress::extractDir("a.zip", "b");
            }
            
            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 15 Dec 2016, 09:09 last edited by
            #5

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

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M mrdebug
              15 Dec 2016, 08:56

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

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

              the probgram goes to crash.

              .pro

              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
              }
              

              main.cpp

              #include "quazip/quazip.h"
              #include "QFile"
              #include "QDebug"
              
              #include <quazip/JlCompress.h>
              
              MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
                  ui->setupUi(this);
                  JlCompress::extractDir("a.zip", "b");
              }
              
              V Offline
              V Offline
              VRonin
              wrote on 15 Dec 2016, 09:31 last edited by VRonin
              #6

              @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

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              2
              • M Offline
                M Offline
                mrdebug
                wrote on 15 Dec 2016, 10:08 last edited by
                #7

                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?

                Need programmers to hire?
                www.labcsp.com
                www.denisgottardello.it
                GMT+1
                Skype: mrdebug

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  VRonin
                  wrote on 15 Dec 2016, 11:25 last edited by VRonin
                  #8

                  yes with http://quazip.sourceforge.net/classQuaZip.html#ae52ebadd5ce64cdb49d7e198904b0b8c
                  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 http://doc.qt.io/qt-5/qbytearray.html#qCompress and below

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  2
                  • M Offline
                    M Offline
                    mrdebug
                    wrote on 15 Dec 2016, 16:02 last edited by
                    #9

                    Someting like this?

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

                    returns false...

                    Need programmers to hire?
                    www.labcsp.com
                    www.denisgottardello.it
                    GMT+1
                    Skype: mrdebug

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 15 Dec 2016, 16:26 last edited by VRonin
                      #10

                      QuaZipFile represents a file inside a zip file, not a zip file in itself. the constructor you are calling is this one: http://quazip.sourceforge.net/classQuaZipFile.html#a1349ad27f1947bc3e346d83dbf9586c4 use QuaZip instead.

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

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        mrdebug
                        wrote on 9 Jan 2017, 07:38 last edited by
                        #11

                        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.

                        Need programmers to hire?
                        www.labcsp.com
                        www.denisgottardello.it
                        GMT+1
                        Skype: mrdebug

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 9 Jan 2017, 23:02 last edited by
                          #12

                          Hi,

                          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.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mrdebug
                            wrote on 10 Jan 2017, 07:31 last edited by
                            #13

                            Please have a look at this sequence:

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

                            Need programmers to hire?
                            www.labcsp.com
                            www.denisgottardello.it
                            GMT+1
                            Skype: mrdebug

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              VRonin
                              wrote on 10 Jan 2017, 08:26 last edited by VRonin 1 Oct 2017, 08:29
                              #14

                              You have to open the QuaZip for decompression first:

                                  QBuffer storageBuff(&QBABufferOut);
                                  QuaZip zip(&storageBuff);
                                  if (!zip.open(QuaZip::mdUnzip))
                                      qDebug() << "error";
                                  QuaZipFile file(&zip);
                                  for (bool f = zip.goToFirstFile(); f; f = zip.goToNextFile()) {
                                      QuaZipFileInfo fileInfo;
                                      file.getFileInfo(&fileInfo);
                                      qDebug() << fileInfo.name;
                                      file.open(QIODevice::ReadOnly);
                                      
                                      qDebug() << "Content: " << file.readAll().toBase64();
                                      file.close();
                                  }
                                  zip.close();
                              

                              P.S.

                              // (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

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              1 Reply Last reply
                              4
                              • M Offline
                                M Offline
                                mrdebug
                                wrote on 10 Jan 2017, 09:55 last edited by
                                #15

                                It works perfectly.
                                Many thanks.

                                Need programmers to hire?
                                www.labcsp.com
                                www.denisgottardello.it
                                GMT+1
                                Skype: mrdebug

                                Ramkumar MohanR 1 Reply Last reply 2 Aug 2022, 07:17
                                0
                                • V VRonin
                                  15 Dec 2016, 07:49

                                  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

                                  S Offline
                                  S Offline
                                  SPlatten
                                  wrote on 27 Sept 2021, 23:51 last edited by
                                  #16

                                  @VRonin said in How to manage zip file:

                                  QuaZIP

                                  Is there a license associated with the use of this? As I have a need for compressing large amounts of binary data that I need to transmit to remote clients.

                                  Kind Regards,
                                  Sy

                                  J 1 Reply Last reply 28 Sept 2021, 05:29
                                  0
                                  • S SPlatten
                                    27 Sept 2021, 23:51

                                    @VRonin said in How to manage zip file:

                                    QuaZIP

                                    Is there a license associated with the use of this? As I have a need for compressing large amounts of binary data that I need to transmit to remote clients.

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 28 Sept 2021, 05:29 last edited by
                                    #17

                                    @SPlatten said in How to manage zip file:

                                    Is there a license associated with the use of this?

                                    https://github.com/stachenov/quazip

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    2
                                    • S Offline
                                      S Offline
                                      SPlatten
                                      wrote on 28 Sept 2021, 05:32 last edited by
                                      #18

                                      Thank you,

                                      Kind Regards,
                                      Sy

                                      artwawA 1 Reply Last reply 28 Sept 2021, 14:18
                                      0
                                      • S SPlatten
                                        28 Sept 2021, 05:32

                                        Thank you,

                                        artwawA Offline
                                        artwawA Offline
                                        artwaw
                                        wrote on 28 Sept 2021, 14:18 last edited by
                                        #19

                                        @SPlatten if both ends are in your software I'd suggest agains using 3rd party library. qCompress and qUncompress work just fine in that regard. My usual approach is to supply a header (using QDataStream) with checksum and whatever else is needed, then stream to it output from compression routine. Works sufficiently well, eliminates the need for another dependency.

                                        For more information please re-read.

                                        Kind Regards,
                                        Artur

                                        S 1 Reply Last reply 28 Sept 2021, 14:19
                                        2
                                        • artwawA artwaw
                                          28 Sept 2021, 14:18

                                          @SPlatten if both ends are in your software I'd suggest agains using 3rd party library. qCompress and qUncompress work just fine in that regard. My usual approach is to supply a header (using QDataStream) with checksum and whatever else is needed, then stream to it output from compression routine. Works sufficiently well, eliminates the need for another dependency.

                                          S Offline
                                          S Offline
                                          SPlatten
                                          wrote on 28 Sept 2021, 14:19 last edited by
                                          #20

                                          @artwaw , Thank you, I will have a look.

                                          Kind Regards,
                                          Sy

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved