{
// ...
connect(myProcess,
SIGNAL(error
(QProcess::ProcessError)),
this,
SLOT(checkError
(QProcess::ProcessError)));
connect(myProcess, SIGNAL(started()), this, SLOT(processStarted()));
connect(myProcess,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(processExited
(int,
QProcess::ExitStatus)));
myProcess->start(program, arg);
// .. here you exit the current function and wait for process to start / fail to start
}
void MyClass::processStarted(){
qDebug() << "Hurray ! MyProcess started!";
}
void MyClass
::checkError(QProcess::ProcessError err
){ qDebug() << "Process error: " << err;
}
void MyClass::processExited(int exitCode, QProcessExitStatus status){
qDebug() << "Process exited with code: " <<exitCode << ", status: " << status;
}
{
// ...
QProcess *myProcess = new QProcess(this);
connect(myProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(checkError(QProcess::ProcessError)));
connect(myProcess, SIGNAL(started()), this, SLOT(processStarted()));
connect(myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processExited(int,QProcess::ExitStatus)));
myProcess->start(program, arg);
// .. here you exit the current function and wait for process to start / fail to start
}
void MyClass::processStarted(){
qDebug() << "Hurray ! MyProcess started!";
}
void MyClass::checkError(QProcess::ProcessError err){
qDebug() << "Process error: " << err;
}
void MyClass::processExited(int exitCode, QProcessExitStatus status){
qDebug() << "Process exited with code: " <<exitCode << ", status: " << status;
}
To copy to clipboard, switch view to plain text mode
myProcess->start(program, arg);
qDebug() << myProcess->state(); //Ref 1
qDebug() << myProcess->error(); //Ref 2
QProcess *myProcess = new QProcess(this);
myProcess->start(program, arg);
qDebug() << myProcess->state(); //Ref 1
qDebug() << myProcess->error(); //Ref 2
To copy to clipboard, switch view to plain text mode
will not work correctly in most of the cases, because you check the status and error value of QProcess before it is initialized and started.
Bookmarks