QuaZip库下载地址: https://sourceforge.net/projects/quazip/files/latest/download
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
void uploadAnswerPackege()
{
// 压缩文件
//JlCompress::compressDir(QString("%1.zip").arg(GMethod::instance()->getAnswerName()), DIR_RESULT);
const QString& zipName(QString("%1.zip").arg(DIR_RESULT + GMethod::instance()->getZkzh()));
QuaZip zip(zipName);
if (!zip.open(QuaZip::mdCreate))
{
qDebug("Could not create zip: %s", qPrintable(zipName));
return;
}
const QString& innerName = QString("%1.ans").arg(GMethod::instance()->getZkzh());
QuaZipNewInfo newInfo(innerName);
//生成MD5加密
QByteArray byteArray;
byteArray.append(innerName);
QByteArray hash = QCryptographicHash::hash(byteArray, QCryptographicHash::Md5);
QString strMD5 = hash.toHex();
QuaZipFile file(&zip);
bool ret = file.open(QIODevice::WriteOnly,
newInfo, // QuaZipNewInfo结构体引用
strMD5.toUtf8().constData(), // 密码
0, // CRC值(默认值是0)
8); // 写入方法(0为文件夹,8为普通文件)
if (ret)
{
QFile file2(GMethod::instance()->getAnswerName());
bool isopen = file2.open(QIODevice::ReadOnly);
if (isopen)
{
// 开始写入文件的数据了
file.write(file2.readAll());
}
file2.close();
file.close();
}
zip.close();
ui->stackWidgetExam->setCurrentIndex(PAGE_END);
}