Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
846 views
in Technique[技术] by (71.8m points)

qt - Start a process using 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...