问题
i am working on an application made with Qt5 that downloads a .zip-file to a temporary directory and extracts the .zip-file to a specified directory.
I already managed to download the .zip-file and now I'm trying to extract it using 7zip. I use QProcess to start 7Zip.
Here the file structure of my Qt-build-kit-thingy:
build-ExtractTest-Desktop_Qt_5_3_MSVC2013_64bit-Debug
7za.exe
build
ExtractTest.exe
Here is the code I use for starting the Process:
// 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);
Here is the output of my program (I print all output of 7zip to 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
However when I execute the command from console then 7zip works as expected:
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
So my guess is there is a path problem when executing 7zip via QProcess. I could be wrong though. Anyone any ideas?
PS: I downloaded this random zip-file from here: http://www.eci.org/_media/downloads/eci_2002_target/eci2002win.zip
EDIT: I tried putting QDir::toNativeSeparators()
around the paths to convert to Windows' path seperator:
extractArguments << "-o\"" + QDir::toNativeSeparators(installPath) + "\""; // extract to installdir
extractArguments << "\"" + QDir::toNativeSeparators(currentPath) + "\"";
This doesn't work either. Here is the new console output of my application:
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:
Since Kamil didn't answer, I give it myself:
The correct way to call 7zip is
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 does not like the "
after the -o
.
来源:https://stackoverflow.com/questions/28897273/starting-7zip-from-qprocess-gives-error-cannot-find-archive