I’am trying to call a DOS command: subst with QProcess :
QProcess process;
int returnCode=process.execute(QString("subst " + DLetter+" "+mountPath));
qDebug()<<"returnCode"<<returnCode;
if (returnCode==0){
qDebug()<<"Mount "<<QString("subst " + DLetter+" "+mountPath)
<<"error"<<process.errorString()<<"id"<<process.pid();
process.waitForFinished();
...
}else
qDebug()<<" mounting folder failed "<<process.errorString();
My questions are : Is it enough to call execute() and waitForFinished()? am I safe with calling execute() instead of start ? because I had issues with start() : it didn’t work in all cases(it worked for mounting and didn’t for dismounting folder) .
Any help wil be appreciated.
From the documentation of QProcess::execute() at http://doc.qt.digia.com/qt/qprocess.html#execute
you should do this:
The key is QProcess::execute is a static member function that starts the program, waits for it to finish then returns the exit code of the process.
Note: I had to remove the non static calls to process.waitForFinished() and process.errorString() since neither can work from a static QProcess::execute.