Run the process using QProcess
maybe the code below will help you:
QProcess *process = new QProcess(this); QString program = "explorer.exe"; QString folder = "C:\\"; process->start(program, QStringList() << folder); I think that you are trying to execute a program that does not consist of the global Windows variable $ PATH, so winword.exe does not execute.
You may also need to determine the absolute path to the program, for example:
QString wordPath = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE" process->start(wordPath, QStringList() << ""); From the Qt documentation:
Note. Processes are started asynchronously, which means start () and error () may be delayed. Call waitForStarted () to make sure that the process is running (or failed to start) and that these signals have been emitted.
Connect the signals mentioned in the document to some graphic control or debug output and see what happens. If there is an error, you should check the type of error using QProcess :: error ().
If the method, when you try to start an external process, is finished right after your code, for example:
void foo() { ... QString program = "WINWORD.EXE"; process->start(program); } and variable
process was declared as a local variable, it will be destroyed at the end of the method, and no external process will be launched - or you won’t see it correctly, because it will be destroyed immediately after launch.
This was the cause of a similar problem in my case. Hope this helps.
You can simply set the working directory:
myProcess = new QProcess(); myProcess->setWorkingDirectory("C:\\Z-Programming_Source\\Java-workspace\\Encrypt1\\bin\\"); Or do it at startup:
myProcess->start("dir \"My Documents\""); In start () you can enter a command for the console ... read the manual.
I prefer the first option. More readable.