Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a process using QProcess

Tags:

qt

qprocess

I'm trying to start Microsoft word using QProcess as following:

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

but nothing happens. winword.exe is on path (so when i type winword.exe word is openning up). Is it the right way to do so ?

like image 531
kaycee Avatar asked Apr 12 '10 14:04

kaycee


People also ask

How do I start a QT process?

To start a process, pass the name and command line arguments of the program you want to run as arguments to start(). Arguments are supplied as individual strings in a QStringList. Alternatively, you can set the program to run with setProgram() and setArguments(), and then call start() or open().

How do I cancel QProcess?

void QProcess::kill () const [slot] The nice way to end a process and to be sure that it is finished, is to do something like this: process->tryTerminate(); QTimer::singleShot( 5000, process, SLOT( kill() ) );

How can I get Qt process ID?

We can see, PID value from Qt : QProcess get PID is equal with PID from konsole command. You can get the complete source code from Qt : QProcess get PID in here.


2 Answers

may be code below will help you:

QProcess *process = new QProcess(this);
QString program = "explorer.exe";
QString folder = "C:\\";
process->start(program, QStringList() << folder);

I think you are trying to execute program that doesn't consists in global $PATH windows variable, that's why winword.exe doesn't executes.

Also you may need to define absolute path to program, e.g.:

QString wordPath = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE"
process->start(wordPath, QStringList() << "");
like image 83
mosg Avatar answered Sep 21 '22 15:09

mosg


For me, I need to add " characteres :

m_process->start("\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\"");
like image 39
miko53 Avatar answered Sep 20 '22 15:09

miko53