Qt 压缩和解压缩文件
压缩文件:
1 void compress(const QString uncompressedFile, const QString compressedFile)
2 {
3 QFile uncompressed(uncompressedFile);
4 QFile compressed(compressedFile);
5 if (uncompressed.open(QFile::ReadOnly) && compressed.open(QFile::WriteOnly))
6 {
7 compressed.write(qCompress(uncompressed.readAll(), 9));
8 uncompressed.close();
9 compressed.close();
10 }
11 }
解压缩文件:
1 void uncompress(const QString compressedFile, const QString uncompressedFile)
2 {
3 QFile compressed(compressedFile);
4 QFile uncompressed(uncompressedFile);
5 if (compressed.open(QFile::ReadOnly) && uncompressed.open(QFile::WriteOnly))
6 {
7 uncompressed.write(qUncompress(compressed.readAll()));
8 compressed.close();
9 uncompressed.close();
10 }
11 }