bool unzip(const QString& in_file_path, const QString& out_file_path)
{
QuaZip archive(in_file_path);
if (!archive.open(QuaZip::mdUnzip))
return false;
QString path = out_file_path;
if (!path.endsWith("/") && !out_file_path.endsWith("\\"))
path += "/";
QDir dir(out_file_path);
if (!dir.exists())
dir.mkpath(out_file_path);
for( bool f = archive.goToFirstFile(); f; f = archive.goToNextFile() )
{
QString filePath = archive.getCurrentFileName();
QuaZipFile zFile(archive.getZipName(), filePath);
zFile.open(QIODevice::ReadOnly );
QByteArray ba = zFile.readAll();
zFile.close();
if (filePath.endsWith("/"))
{
dir.mkpath(filePath);
}
else
{
QFile dstFile(path + filePath);
if (!dstFile.open(QIODevice::WriteOnly))
return false;
dstFile.write(ba);
dstFile.close();
}
}
return true;
}
源于:http://blog.csdn.net/kfbyj/article/details/13888101
证实可用.