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. .DAT file not extracted using Quazip library in qt
QtWS25 Last Chance

.DAT file not extracted using Quazip library in qt

Scheduled Pinned Locked Moved Solved General and Desktop
quazipextractzipfilefile read
8 Posts 3 Posters 834 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.
  • H Offline
    H Offline
    HemantSuryawanshi
    wrote on 28 May 2021, 04:42 last edited by
    #1

    I am trying to extract .DAT file using Quazip library in Qt 5.14. I integrated this quazip library into my project and try to extract files using it. .txt file is get extracted but .DAT file is not get extracted. .DAT files are created but it does not contain any data. Here is my source code

    bool fileHelper::extractAll( QString folderPath, QString filePath ) {
        QuaZip zip(filePath);
        zip.open(QuaZip::mdUnzip);
        bool isSuccess = false;
        for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile())
        {
            // set source file in archive
            QString filePath = zip.getCurrentFileName();
            QuaZipFile zFile( zip.getZipName(), filePath );
            // open the source file
            zFile.open( QIODevice::ReadOnly );
            // create a bytes array and write the file data into it
            //QByteArray ba = zFile.read()
            QByteArray ba = zFile.readAll();
            // close the source file
            zFile.close();
            // set destination file
            //QFile dstFile( getfileStoreRootDir()+filePath );
            QFile dstFile( folderPath+filePath );
            qDebug() << "dstFile :" << dstFile;
            // open the destination file
            dstFile.open( QIODevice::WriteOnly | QIODevice::Text );
            // write the data from the bytes array into the destination file
            dstFile.write( ba.data() );
            //close the destination file
            dstFile.close();
            //mark extraction sucess
            isSuccess = true;
        }
        zip.close();
        return isSuccess; 
    }
    

    Please tell me am I doing something wrong or any other extra flag or something is required for it.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 May 2021, 05:26 last edited by
      #2

      You should check if the file which not gets extracted really contains data with another program which can extract zip files.
      Then add some debug output to see the size of ba which is returned by zFile.readAll(). Also IODevice::Text is for sure not correct for non text-files.
      And you should check if QFile::open() and write() really succeed - they have return values for a reason...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • H Offline
        H Offline
        HemantSuryawanshi
        wrote on 28 May 2021, 06:54 last edited by
        #3

        yes I tried that. if I directly extract zip file then the 3mb file is created but when I tried to extract using code then 0kb file is created. and I also print debug log for ba, it prints nothing.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 28 May 2021, 06:55 last edited by
          #4

          Then there seems to be a problem inside QUAZip - nothing we can do against.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HemantSuryawanshi
            wrote on 28 May 2021, 06:56 last edited by
            #5

            so can you suggest any other library or method which solves this problem

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 28 May 2021, 07:01 last edited by
              #6

              QUZiap is open source. Simply debug into the functions to see what's going wrong in there.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 28 May 2021, 08:13 last edited by VRonin
                #7

                Try this:

                bool fileHelper::extractAll(QString folderPath, QString filePath) {
                    QuaZip zip(filePath);
                    if(!zip.open(QuaZip::mdUnzip))
                        return false;
                    QuaZipFile file(&zip);
                    for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()){
                        if(!file.open(QIODevice::ReadOnly))
                            return false;
                        QFile dstFile(folderPath+zip.getCurrentFileName());
                        if(!dstFile.open(QIODevice::WriteOnly))
                            return false;
                        while(!file.atEnd())
                            dstFile.write(file.read(1024*1024));
                        dstFile.close();
                        file.close();
                    }
                    zip.close();
                    return true;
                }
                

                If it still doesn't work

                can you suggest any other library

                KArchive https://api.kde.org/frameworks/karchive/html/index.html

                "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
                • H Offline
                  H Offline
                  HemantSuryawanshi
                  wrote on 29 May 2021, 08:42 last edited by
                  #8

                  it worked. thanks @VRonin

                  1 Reply Last reply
                  0

                  4/8

                  28 May 2021, 06:55

                  • Login

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