Skip to content

QuaZip

1 解压

class UnzipDicomFile : public QThread {
    Q_OBJECT
  public:
    explicit UnzipDicomFile() {}
    virtual ~UnzipDicomFile() override {}
    virtual void run() override;
    void SetPath(const QString &path);
  private:
    QString path_;
};

//-------------------------------------------------------
void UnzipDicomFile::run() {
    Kiss::FileUtil::DirRemove("./ZipCache");
    Kiss::FileUtil::DirMake("./ZipCache/");
    JlCompress::extractDir(this->path_, "./ZipCache/");
}

//-------------------------------------------------------
void UnzipDicomFile::SetPath(
    const QString &path) {
    this->path_ = path;
}

2 使用

保留之前的打开文件逻辑,如果当前返回的只有一个文件并且后缀是 .zip 则使用 UnzipDicomFile 先解压到本地 "./ZipCache"。让后读取这个文件夹。全部载入后删除本地 "./ZipCache"

void ThumbnailBarWidget::appendImagePaths(
    const QStringList &paths, bool clear_old) {
    emit Signal_ImageLoadBegin();
    if(1 == paths.size() && paths.first().right(4) == ".zip") {
        QPointer<UnzipDicomFile> script_recoery_;
        script_recoery_ = new UnzipDicomFile();
        connect(script_recoery_, &UnzipDicomFile::finished,
        this, [&] {
            appendImagePaths(QStringList() << "./ZipCache", true);
        });
        connect(script_recoery_, &UnzipDicomFile::finished,
                script_recoery_, &UnzipDicomFile::deleteLater);
        script_recoery_->SetPath(paths.first());
        script_recoery_->start();
        return;
    }
/*
    原先打开文件方法
*/
    Kiss::FileUtil::DirRemove("./ZipCache");
    emit Signal_ImageLoadFinished();