2 bobo rabbit bobo_rabbit 于 2015.07.01 14:39 提问

Qt怎么实现解压缩和压缩文件的功能

Qt怎么实现解压缩和压缩文件的功能t怎么实现解压缩和压缩文件的功能,不想调用本地的rar指令。第三方库Quezip稳定吗,在哪里可以找到比较全的源码。

2个回答

max_min_
max_min_   Rxr 2015.07.02 12:32

有开源的库的,
或者自己根据压缩,解压的原理,简单实现一个也是可以。
google下,都是有做好的。
老早前玩过,

oyljerry
oyljerry   Ds   Rxr 2015.07.06 12:15
#include <QCoreApplication>
#include <QByteArray>
#include <QBitArray>
#include <QString>
#include <QDebug>
#include <QFile>

void Zip(QString filename , QString zipfilename);
void Unzip(QString zipfilename , QString filename);

int main(int argc, char *argv[]) {

    QCoreApplication a(argc, argv);

    //zipping
    Zip("D:\\programs\\demo.txt","D:\\programs\\demo.zip");
    qDebug() << "Done zipping";

    //unzipping
    Unzip("D:\\programs\\demo.zip","D:\\programs\\demo_unzipped.txt");
    qDebug() << "Done unzipping";

    return a.exec();
}

void Zip (QString filename , QString zipfilename){

    QFile infile(filename);
    QFile outfile(zipfilename);
    infile.open(QIODevice::ReadOnly);
    outfile.open(QIODevice::WriteOnly);
    QByteArray uncompressedData = infile.readAll();
    QByteArray compressedData = qCompress(uncompressedData,9);
    outfile.write(compressedData);
    infile.close();
    outfile.close();
}

void Unzip (QString zipfilename , QString filename){
    QFile infile(zipfilename);
    QFile outfile(filename);
    infile.open(QIODevice::ReadOnly);
    outfile.open(QIODevice::WriteOnly);
    QByteArray uncompressedData = infile.readAll();
    QByteArray compressedData = qUncompress(uncompressedData);
    outfile.write(compressedData);
    infile.close();
    outfile.close();
}
.pro file

QT       += core

QT       -= gui

TARGET = TestZippingExample
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

http://karanbalkar.com/2014/02/zipping-and-unzipping-files-using-qt-5-framework/

Csdn user default icon
上传中...
上传图片
插入图片