在 Qt(C++) 中使用 QProcess 解压缩 - 提取目录问题

Unzip with WinRar in Qt(C++) using QProcess - extract directory problem

本文关键字:解压缩 提取 问题 QProcess Qt C++      更新时间:2023-10-16

我有这段代码来解压缩文件夹。它可以工作,但我不知道如何更改提取目录。每次,它都会将文件夹提取到我的程序.exe文件的目录中。我尝试了一些东西,但每次,它只是在那里提取。我想选择目录。

QString program = "c:/program files/winRAR/winRAR.exe";
QStringList arguments;
arguments << "x"; // extract files and directories
arguments << "-y"; // suppress questions
arguments << "-o" + QDir::toNativeSeparators(extractDirectory);
arguments << QDir::toNativeSeparators(zipFileDirectory);
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

我会说,在 -o 参数后面编写 extractDirectory 存在问题,但不确定。 感谢您的任何帮助。

感谢一些评论,我发现 -o 参数在 WinRAR 中不存在,这是解决方案。

QString program = "c:/program files/winRAR/winRAR.exe";
QStringList arguments;
arguments << "x"; // extract files and directories
arguments << "-y"; // suppress questions
arguments << QDir::toNativeSeparators(zipFileDirectory);
arguments << QDir::toNativeSeparators(extractDirectory);
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

谢谢大家。