My function just initializes the the QProcess as above and tries to run it
And it does not wait for it to start and does not check for error values.
Qt Code:
  1. {
  2. // ...
  3. QProcess *myProcess = new QProcess(this);
  4. connect(myProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(checkError(QProcess::ProcessError)));
  5. connect(myProcess, SIGNAL(started()), this, SLOT(processStarted()));
  6. connect(myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processExited(int,QProcess::ExitStatus)));
  7. myProcess->start(program, arg);
  8. // .. here you exit the current function and wait for process to start / fail to start
  9. }
  10.  
  11. void MyClass::processStarted(){
  12. qDebug() << "Hurray ! MyProcess started!";
  13. }
  14.  
  15. void MyClass::checkError(QProcess::ProcessError err){
  16. qDebug() << "Process error: " << err;
  17. }
  18.  
  19. void MyClass::processExited(int exitCode, QProcessExitStatus status){
  20. qDebug() << "Process exited with code: " <<exitCode << ", status: " << status;
  21. }
To copy to clipboard, switch view to plain text mode 

Alternative is to call waitForFinished() after start(), but this can freeze the gui.
It is important to understand the asynchronous nature of QProcess, this:
Qt Code:
  1. QProcess *myProcess = new QProcess(this);
  2. myProcess->start(program, arg);
  3.  
  4. qDebug() << myProcess->state(); //Ref 1
  5. 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.