QProcess + 7zip how to Extract file
-
Hi to all,
i've to extract all file in a subdirectory with the same name of archive from a bvc file
using 7zip consolemainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QProcess> #include <QDir> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_Estrai_clicked() { QString programma = "comando.cmd"; QString comando = "7z x -y -o" + QDir::currentPath() + "/* " + QDir::currentPath() + "/*.bvc"; QProcess UnZip; UnZip.setProgram(programma); UnZip.setArguments(QStringList(comando)); UnZip.setWorkingDirectory(QDir::currentPath()); UnZip.start(); UnZip.waitForFinished(); int S = UnZip.exitStatus(); qDebug() << "Exit Status" << S; int C = UnZip.exitCode(); qDebug() << "Exit Code" << C; int E = UnZip.error(); qDebug() << "Error" << E; }
comando.cmd (located in: C:\Users\tecni\Desktop\TaglioLaser )
C:\Program Files\7-Zip\7z.exe
Application Output
08:34:02: Starting C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe...
argomenti "7z x -y -oC:/Users/tecni/Desktop/TaglioLaser/* C:/Users/tecni/Desktop/TaglioLaser/*.bvc"
Working Directory "C:/Users/tecni/Desktop/TaglioLaser"
Exit Status 0
Exit Code 1
Error 5
08:34:24: C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe exited with code 07zip exit code:
Exit Codes from 7-Zip
7-Zip returns the following exit codes:Code Meaning
0 No error
1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2 Fatal error
7 Command line error
8 Not enough memory for operation
255 User stopped the processQProcess Error
enum QProcess::ProcessError
This enum describes the different types of errors that are reported by QProcess.
Constant Value Description
QProcess::FailedToStart 0 The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program.
QProcess::Crashed 1 The process crashed some time after starting successfully.
QProcess::Timedout 2 The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.
QProcess::WriteError 4 An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
QProcess::ReadError 3 An error occurred when attempting to read from the process. For example, the process may not be running.
QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().Any ideas??
Thanks in advance -
Hi to all,
i've to extract all file in a subdirectory with the same name of archive from a bvc file
using 7zip consolemainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QProcess> #include <QDir> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_Estrai_clicked() { QString programma = "comando.cmd"; QString comando = "7z x -y -o" + QDir::currentPath() + "/* " + QDir::currentPath() + "/*.bvc"; QProcess UnZip; UnZip.setProgram(programma); UnZip.setArguments(QStringList(comando)); UnZip.setWorkingDirectory(QDir::currentPath()); UnZip.start(); UnZip.waitForFinished(); int S = UnZip.exitStatus(); qDebug() << "Exit Status" << S; int C = UnZip.exitCode(); qDebug() << "Exit Code" << C; int E = UnZip.error(); qDebug() << "Error" << E; }
comando.cmd (located in: C:\Users\tecni\Desktop\TaglioLaser )
C:\Program Files\7-Zip\7z.exe
Application Output
08:34:02: Starting C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe...
argomenti "7z x -y -oC:/Users/tecni/Desktop/TaglioLaser/* C:/Users/tecni/Desktop/TaglioLaser/*.bvc"
Working Directory "C:/Users/tecni/Desktop/TaglioLaser"
Exit Status 0
Exit Code 1
Error 5
08:34:24: C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe exited with code 07zip exit code:
Exit Codes from 7-Zip
7-Zip returns the following exit codes:Code Meaning
0 No error
1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2 Fatal error
7 Command line error
8 Not enough memory for operation
255 User stopped the processQProcess Error
enum QProcess::ProcessError
This enum describes the different types of errors that are reported by QProcess.
Constant Value Description
QProcess::FailedToStart 0 The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program.
QProcess::Crashed 1 The process crashed some time after starting successfully.
QProcess::Timedout 2 The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.
QProcess::WriteError 4 An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
QProcess::ReadError 3 An error occurred when attempting to read from the process. For example, the process may not be running.
QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().Any ideas??
Thanks in advance@TheCipo76 said in QProcess + 7zip how to Extract file:
UnZip.setArguments(QStringList(comando));
You have to pass the arguments as a list of strings for each element. You have simply created a single element holding all the arguments. Hence it won't work.
If after the command finishes you printed out what arrived on standard output/error, you would presumably a suitable error message from the command.
You do not say and I don't know whatcomando.cmd
is as a program or what it does with its arguments, so actually behaviour depends on that. Answer this first, as it determines how you must pass arguments to it correctly.Oh:
comando.cmd (located in: C:\Users\tecni\Desktop\TaglioLaser )
C:\Program Files\7-Zip\7z.exe
OK, I don't understand what you are trying to do. If
comando.cmd
contains only the7z.exe
line you show then where are you passing any arguments to it to get it do the unzipping??Furthermore it won't be correct anyway: because that path contains a space character it will need to be quoted:
"C:\Program Files\7-Zip\7z.exe"
And what is the
7z
doing at the start of the arguments??You need to get yourself to a point where you have a command which works right outside of
QProcess::start()
before you can get that right/working. -
Hi to all,
i've to extract all file in a subdirectory with the same name of archive from a bvc file
using 7zip consolemainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QProcess> #include <QDir> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_Estrai_clicked() { QString programma = "comando.cmd"; QString comando = "7z x -y -o" + QDir::currentPath() + "/* " + QDir::currentPath() + "/*.bvc"; QProcess UnZip; UnZip.setProgram(programma); UnZip.setArguments(QStringList(comando)); UnZip.setWorkingDirectory(QDir::currentPath()); UnZip.start(); UnZip.waitForFinished(); int S = UnZip.exitStatus(); qDebug() << "Exit Status" << S; int C = UnZip.exitCode(); qDebug() << "Exit Code" << C; int E = UnZip.error(); qDebug() << "Error" << E; }
comando.cmd (located in: C:\Users\tecni\Desktop\TaglioLaser )
C:\Program Files\7-Zip\7z.exe
Application Output
08:34:02: Starting C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe...
argomenti "7z x -y -oC:/Users/tecni/Desktop/TaglioLaser/* C:/Users/tecni/Desktop/TaglioLaser/*.bvc"
Working Directory "C:/Users/tecni/Desktop/TaglioLaser"
Exit Status 0
Exit Code 1
Error 5
08:34:24: C:\Users\tecni\Documents\ProgettiQt\build-prova-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\debug\prova.exe exited with code 07zip exit code:
Exit Codes from 7-Zip
7-Zip returns the following exit codes:Code Meaning
0 No error
1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2 Fatal error
7 Command line error
8 Not enough memory for operation
255 User stopped the processQProcess Error
enum QProcess::ProcessError
This enum describes the different types of errors that are reported by QProcess.
Constant Value Description
QProcess::FailedToStart 0 The process failed to start. Either the invoked program is missing, or you may have insufficient permissions or resources to invoke the program.
QProcess::Crashed 1 The process crashed some time after starting successfully.
QProcess::Timedout 2 The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.
QProcess::WriteError 4 An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
QProcess::ReadError 3 An error occurred when attempting to read from the process. For example, the process may not be running.
QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().Any ideas??
Thanks in advance -
T TheCipo76 has marked this topic as solved on