1

I am using QProcess on Windows and I have a problem running an exe file that is located in Program Files. Trying to run the same with the CreateProcess() function works ok. Space in the path is not the problem. I think it is related to user access rights or something similar. I can use the CreateProcess() but I would like to know if there is any way how to get QProcess working as I need.

My code looks like this:

QProcess* myProcess = new QProcess(this);
myProcess->setProcessEnvironment(myEnvVars);
myProcess->start("myExePath");

Edit: My platform is Visual Studio 2015 and Qt 4.71

ni1ight
  • 327
  • 4
  • 12
  • 2
    I think It relates to access right. Try to call GetLastError function after creating the process, the returned value should be 5, or launch your application with administrator rights, to be sure that problem connected with access rights. – arturx64 May 02 '17 at 09:56
  • Try to call waitForStarted() method after start. – arturx64 May 02 '17 at 10:00
  • 2
    Why are you sure about spaces? The CreateProcess and the QProcess::start method you are using treats the string you provide differently - may be the same issue as [in this question](http://stackoverflow.com/questions/14637539/createprocess-can-start-a-process-but-qprocess-cannot-why) – Mikhail Churbanov May 02 '17 at 11:24
  • @MikhailChurbanov Yes I know that question but it is not this case. I did several tests to be sure. – ni1ight May 02 '17 at 11:27
  • @ni1ight, that's strange then. I would suggest using the `setCreateProcessArgumentsModifier` with the same configuration you used for the `CreateProcess` that is working. Cause the start method actually calls it inside. There might be an issue with the Pipes set instead standard IO in QProcess, or usage of handles inheritance by default... – Mikhail Churbanov May 02 '17 at 11:53
  • Try to run your main application with admin rights this should work. – SourabhKus May 02 '17 at 13:14

1 Answers1

0

I had the same issue and I have used startDetached Method and it worked.

QProcess* myProcess = new QProcess(this);
myProcess->setProcessEnvironment(myEnvVars);
myProcess->startDetached("myExePath");
  • Thanks but I've tried this option too. In this case, the problem is environment variables. You can find more here: http://stackoverflow.com/questions/4265946/set-environment-variables-for-startdetached-qprocess – ni1ight May 12 '17 at 10:15