Qt下压缩解压文件夹(2)Qzipwriter Qzipreader

使用了Qt的库来进行压缩解压的。

修改pro文件

QT       += gui-private

导入头文件

#include 
#include 

压缩

void zipWriter(QString path)
{
    QZipWriter *writer = new QZipWriter(path + "/test.zip");
    //添加文件夹
//    writer->addDirectory(path + "/ss");
    //添加文件
    QFile file(path + "/test.txt");
    if (!file.exists())
    {
        return;
    }
    file.open(QIODevice::ReadOnly);
    writer->addFile("test.txt", file.readAll());
    file.close();
    writer->close();
}

解压

void zipReader(QString path)
{
    QZipReader reader(path + "/test.zip");
    reader.extractAll(path);

    QFile file(path);
    file.open(QIODevice::WriteOnly);
    file.write(reader.fileData(QString::fromLocal8Bit("%1").arg(path + "/Desktop")));
    file.close();
    reader.close();
}

 

你可能感兴趣的:(Qt)