use QProcess to start an unzip utility e.g. 7z or equivalent.
use QProcess to start an unzip utility e.g. 7z or equivalent.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Is there anyway to do it without using QProcess? I am trying to avoid needing to install any third party software with my application.
Ok so I have decided to use peazip for the QProcess but I do not understand how to use QProcess very well. I downloaded the peazip portable and placed the executable in the same directory as my application. I tried to do the following:
Qt Code:
MainWindow::open() { QStringList arguments; arguments << "-ext2here" << "file.tar.gz"; unarchive->start("peazip", arguments); // other things happen }To copy to clipboard, switch view to plain text mode
Unfortunately nothing seems to be happening so I am curious what I am missing. Thanks for any help!
What sort of 'nothing' is happening? Is the QProcess object emitting an error() signal? Where is the peazip executable in relation to the current working directory of your process?
how are you testing? by debugging through an IDE or just running your program 'manually'? If the former, you probably just have a problem where your app is not run from the same location as the unzip utility
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Duh! I was running it in debug mode and didn't put the peazip executable in the correct directory... It seems to be working fine now!!
I do have another question that might be answered here, can you do an OS check with Qt? I don't see a Linux version of the peazip portable so I am thinking I will need a #if statement to check for Windows OS and use peazip but if it is Linux use standard unix unarchiving/archiving commands. How would you call the unix terminal to unzip and untar a file?
Thanks again for any help!
So I am able to have the QProcess execute the unzip and untar but when I try and run something after the untar nothing appears to be happening.
Qt Code:
{ if(okToContinue()) { QString fileName = QFileDialog::getOpenFileName(this, tr("Open file.tar.gz file"), ".", tr("gzip tarball" "(*.tar.gz)")); if(!fileName.isEmpty()) { QStringList arguments; arguments << "-ext2here" << fileName; unarchive->start("peazip", arguments); if(unarchive->waitForFinished()) { fileName.remove(".gz"); arguments.clear(); arguments << "-ext2here" << fileName; int exitCode = unarchive->execute("peazip", arguments); if(unarchive->waitForFinish()) { fileName.remove("file.tar"); // this is the path that is extracted from tar and the .csv is what I am after fileName.append(("tmp/file/A.csv")); loadFile(fileName); } } } } }To copy to clipboard, switch view to plain text mode
It never seems to make it inside the second waitForFinish if statement. What am I doing wrong?
Thanks for help!
why are you mixing execute/start? Why are you allocating on the heap when you only want a local instance?
I believe the problem is that you are using execute, which is a static method, therefore the finished state required for 'waitForFinished' is not modified.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Bookmarks