其他分享
首页 > 其他分享> > Qt 压缩和解压缩文件

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 }

 

标签:QString,Qt,QFile,uncompressed,压缩文件,uncompressedFile,compressed,close,和解
来源: https://www.cnblogs.com/yitouniu/p/16557743.html