start(pr...">

Run the process using QProcess

I am trying to run a Microsoft word using QProcess as follows:

 QString program = "WINWORD.EXE"; process->start(program); 

but nothing happens. winword.exe is on the way (so when I type the word winword.exe it opens). Is it correct?

+4
source share
6 answers

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() << ""); 
+12
source

For me I need to add "characters:

 m_process->start("\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""); 
+5
source

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 ().

+1
source

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.

0
source

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.

0
source
 QProcess *pro = new QProcess; QString s = "\"C:\Users\xyz\Desktop\Example.exe"; pro ->start(s); 
0
source

Source: https://habr.com/ru/post/1306704/


All Articles