RK3588开发板中使用Qt对zip文件进行解压

操作步骤:

  1. 下载源码quazip-0.7.3.zip ,在网上找找下载地址
  2. 上传源码进行解压,然后使用命令
    cd quazip-0.7.3
    qmake
    make
  3. 主要用的是quazip-0.7.3/quazip这个里面的源码,然后把源码加入到自己创建的qt项目pro中,导入方式选中项目鼠标右键Add Libary,并导入quazip源码和对应的so库文件
  4. 解压文件代码
cpp 复制代码
 /**文件解压
 * @brief extractFolder
 * @param zipFilePath 解压文件的路径
 * @param extractPath  解压到哪个目录下
 */
bool  extractFolder(const QString& zipFilePath, const QString& extractPath) {
    // 打开 ZIP 文件
    QuaZip zip(zipFilePath);
    if (!zip.open(QuaZip::mdUnzip)) {
        qDebug() << "Failed to open ZIP file";
        return false;
    }
    QDir().mkpath(extractPath);
    // 枚举 ZIP 文件中的所有条目
    QuaZipFileInfo info;
    QuaZipFile zipFile(&zip);
    for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) {
        if (!zip.getCurrentFileInfo(&info)) {
            qDebug() << "Failed to get file info";
            return false;
        }
        // 提取文件
        if (!zipFile.open(QIODevice::ReadOnly)) {
            qDebug() << "Failed to open file inside ZIP";
            return false;
        }
        QString filePath = extractPath + "/" + info.name;
        QDir().mkpath(QFileInfo(filePath).absolutePath());
        QFile outFile(filePath);
        if (!outFile.open(QIODevice::WriteOnly)) {
            qDebug() << "Failed to create output file" << filePath;
            return false;
        }
        outFile.write(zipFile.readAll());
        outFile.close();
        zipFile.close();
    }
    // 关闭 ZIP 文件
    zip.close();
    return true;
}
相关推荐
用户8055336980316 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner17 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner10 天前
DicomViewer (目录调整) 2
qt
xcyxiner11 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00612 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术12 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript