从QProcess启动7zip会出现错误“找不到存档”

时间:2015-03-06 10:54:34

标签: qt path 7zip qprocess

我正在研究用Qt5制作的应用程序,它将.zip文件下载到临时目录并将.zip文件解压缩到指定目录。

我已经设法下载.zip文件,现在我尝试使用7zip提取它。我使用QProcess启动7Zip。

这是我的Qt-build-kit-thingy的文件结构:

build-ExtractTest-Desktop_Qt_5_3_MSVC2013_64bit-Debug
    7za.exe
    build
        ExtractTest.exe

以下是我用于启动流程的代码:

// assemble extraction command
QString extractProgram = "7za.exe";
QStringList extractArguments;
extractArguments << "x"; // extract files and directories
extractArguments << "-y"; // suppress questions
extractArguments << "-o\"" + installPath+"\""; // extract to installdir
extractArguments << "\""+currentPath +"\"";

std::cout << extractProgram.toStdString() << " " << extractArguments.join(" ").toStdString() << std::endl;

// start extraction
extractionProcess.start(extractProgram, extractArguments);

这是我程序的输出(我将7zip的所有输出打印到stdout):

7za.exe x -y -o"D:\Projects\build-ExtractTest-Desktop_Qt_5_3_MSVC2013_OpenGL_32bit-Debug\BlaBla" "C:/Users/js/AppData/Local/Temp/eci2002win.zip"
started

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


Error:
cannot find archive


0

然而,当我从控制台执行命令时,7zip按预期工作:

D:\Projects\build-ExtractTest-Desktop_Qt_5_3_MSVC2013_64bit-Debug>7za.exe x -y -o"D:\Projects\build-ExtractTest-Desktop_Qt_5_3_MSVC2013_OpenGL_32bit-Debug\BlaBla" "C:/Users/js/AppData/Local/Temp/eci2002win.zip"

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: C:\Users\js\AppData\Local\Temp\eci2002win.zip

Extracting  ECI-Target VisualLayout.csv
Extracting  DataSet CrossReference.xls
Extracting  ECI2002 RandomLayoutCmyk1485-LZW.tif
Extracting  ECI2002 VisualLayoutCmyk1485-LZW.tif
Extracting  ECI-Target RandomLayout.csv
Extracting  ColorTargetRecommendation.pdf
Extracting  SampleDataSet Sorted by ID.txt
Extracting  SampleDataSet Sorted by Loc.txt

Everything is Ok

Files: 8
Size:       1978871
Compressed: 504660

所以我的猜测是通过QProcess执行7zip时存在路径问题。我可能错了。任何想法?

PS:我从这里下载了这个随机zip文件:http://www.eci.org/_media/downloads/eci_2002_target/eci2002win.zip

编辑:我尝试将QDir::toNativeSeparators()放在路径周围转换为Windows&#39;路径分离器:

extractArguments << "-o\"" + QDir::toNativeSeparators(installPath) + "\""; // extract to installdir
extractArguments << "\"" + QDir::toNativeSeparators(currentPath) + "\"";

这也不起作用。这是我的应用程序的新控制台输出:

7za.exe x -y -o"D:\Projects\ExtractTest\build-Verpacker2-Desktop_Qt_5_3_MSVC2013_OpenGL_32bit-Debug\BlaBla" "C:\Users\JanS\AppData\Local\Temp\eci2002win.zip"
started

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18


Error:
cannot find archive

1 个答案:

答案 0 :(得分:1)

由于卡米尔没有回答,我自己给出了:

调用7zip的正确方法是

7za.exe x -y "-oD:\Projects\ExtractTest\build-Verpacker2-Desktop_Qt_5_3_MSVC2013_OpenGL_32bit-Debug\BlaBla" "C:\Users\JanS\AppData\Local\Temp\eci2002win.zip"

7zip不喜欢"之后的-o