-3

I want to run an external process, but this code does not work.

QStringList args;
QString path = "C:\Users\User\Documents\visual studio 2010\Projects\Avito Main\Avito Main\Debug";

QProcess* child = new QProcess();
child->setWorkingDirectory(path);
child->start("a.exe",args);
Martin G
  • 17,357
  • 9
  • 82
  • 98
  • 3
    Did you try to set `"C:\\Users\\User\\Documents\\visual studio 2010\\Projects\\Avito Main\\Avito Main\\Debug"` instead? – vahancho Jul 20 '15 at 08:50
  • 2
    When posting questions, the description "doesn't work" isn't really helping much. Always elaborate on *how* it "doesn't work". Do you get build errors? Then tell us what errors you get. Do you get runtime errors (crashes)? Then run in a debugger to pinpoint the crash and tell us where it is and what the values of the involved variables are. Do you get unexpected results? Then tell us what the actual and expected results are. Something else? Always check for errors (most functions return a success/error indicator), and get the error codes or messages. – Some programmer dude Jul 20 '15 at 08:54
  • 1
    possible duplicate of [start a process using QProcess](http://stackoverflow.com/questions/2622864/start-a-process-using-qprocess) – demonplus Jul 20 '15 at 08:56
  • "C:\\Users\\User\\Documents\\visual studio 2010\\Projects\\Avito Main\\Avito Main\\Debug" doesnt help – Vlad Malihtarovich Jul 20 '15 at 09:16
  • no erros. demonplus, thread didnt help me – Vlad Malihtarovich Jul 20 '15 at 09:20
  • 1
    But ***what happens***? ***How*** doesn't it work? Have you checked the [process state](http://doc.qt.io/qt-5/qprocess.html#state)? Have you checked [the process error code](http://doc.qt.io/qt-5/qprocess.html#error)? – Some programmer dude Jul 20 '15 at 09:40
  • You should give full path for `QProcess::start` – goGud Jul 20 '15 at 11:30

1 Answers1

1

QProcess::setWorkingDirectory sets the working directory for the process itself; it does not make Qt to look for your executable in this path.

So you'll have to pass the full path to the QProcess::start function:

QStringList args;
QString path = "C:/Users/User/Documents/visual studio 2010/Projects/Avito Main/Avito Main/Debug";

QProcess *child = new QProcess();
child->setWorkingDirectory(path);
child->start(path + "/a.exe", args);

Also, note that the "\" characters in your path are used for escape sequences. Use "\\" or "/" instead.

kefir500
  • 4,184
  • 6
  • 42
  • 48