Qt: Simple Example for Quazip

拈花ヽ惹草 提交于 2019-12-21 04:40:51

问题


I built the quazip library. I need a simple example that shows how to unzip a zip File. For example.

Quazip zipFile( QFile("test.zip") );
zipFile.unzip();

Tests shown in quazip is little bit confusing. I searched for a brief amount of time to find an example and I wasn't able to find one.


回答1:


Here is a quick example showing how to read the files. You will need to make some modifications to the code in the loop to write the data to a file or perform whatever operations your application requires:

QuaZip zip("zipFile.zip");
zip.open(QuaZip::mdUnzip);

QuaZipFile file(&zip);

for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()) {
    file.open(QIODevice::ReadOnly);
    //same functionality as QIODevice::readData() -- data is a char*, maxSize is qint64
    file.readData(data,maxSize);
    //do something with the data
    file.close();
}

zip.close();



回答2:


You can use static functions of the class JlCompress. It's very easy to use.

Static Public Member Functions

static bool     compressFile (QString fileCompressed, QString file)
static bool     compressFiles (QString fileCompressed, QStringList files)
static bool     compressDir (QString fileCompressed, QString dir=QString(), bool recursive=true)
static QString  extractFile (QString fileCompressed, QString fileName, QString fileDest=QString())
static QStringList  extractFiles (QString fileCompressed, QStringList files, QString dir=QString())
static QStringList  extractDir (QString fileCompressed, QString dir=QString()) 
static QStringList  getFileList (QString fileCompressed)

Source: http://quazip.sourceforge.net/classJlCompress.html



来源:https://stackoverflow.com/questions/10290083/qt-simple-example-for-quazip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!