Qt World Summit: Submit your Presentation

.DAT file not extracted using Quazip library in qt

  • 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);
        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
            // 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
            //mark extraction sucess
            isSuccess = true;
        return isSuccess; 

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

  • Lifetime Qt Champion

    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...

  • 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.

  • Lifetime Qt Champion

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

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

  • Lifetime Qt Champion

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

  • Try this:

    bool fileHelper::extractAll(QString folderPath, QString filePath) {
        QuaZip zip(filePath);
            return false;
        QuaZipFile file(&zip);
        for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()){
                return false;
            QFile dstFile(folderPath+zip.getCurrentFileName());
                return false;
        return true;

    If it still doesn't work

    can you suggest any other library

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

  • it worked. thanks @VRonin