I would like to launch an executable when pushing a button in my Qt app.
This .exe is always located in the same directory as the Qt app itself.
Sometimes there are white spaces in the path to this directory. This seems to prevent the .exe from starting.
Here is my code (that doesn’t seem to work):
QString path = QCoreApplication::applicationDirPath ();
path.append("/executable.exe");
QProcess process;
process.execute(path);
I don’t know if it is possible to start the .exe without showing a command prompt first.
When the .exe is running I have to close the Qt app, while the .exe keeps running.
execute(QString)uses a single string for both executable path and arguments. Without proper quoting,C:\A path with spaces\foo.exewill be interpreted asc:\Aas executable andpath,withspaces\foo.exeas arguments.To avoid this, use the overload
execute(QString, QStringList)that takes the arguments as separate string list, even if you don’t want to pass arguments at all:This does the right thing and doesn’t require any quoting from your side.