View Full Version : How to call WinWord.exe through the Qt program?

10th October 2009, 08:47
On the window platform, On the assumption that the user don't know the MS word install path, I want to call the winword.exe to open a defaut doc file such as E:/test.doc through the Qt program. The Qt provide a QProcess class to start external programs, but I don't know how to use them. the following is my code, it does not work! Does anyone has some idea? thank you!

QProcess* por = new QProcess(this);
QStringList lst;

10th October 2009, 09:08
what for are you use QObject::tr() function?

10th October 2009, 09:10
and if you write simply WinWord.exe the path that contains this file(WinWord.exe) must be add in a system path.

10th October 2009, 11:20
You are right, if I use the absolute path, the pragram will work. However, I don't want to use absolute path because the pragram don't know the install path of MS word when running on different machines.

10th October 2009, 11:37
However, I don't want to use absolute path because the pragram don't know the install path of MS word when running on different machines.

But you have to. Possible solutions:

create a configure dialog where the user can define the path to the program
create a list of possible locations and check if one of them is valid and then use that path. (use QFile::exists() and may be QDesktopServices::ApplicationsLocation will help you also)
Use Windows api (but don't me about that...)

10th October 2009, 11:50
may be QDesktopServices::openUrl will help?

10th October 2009, 15:11
You can also use QCoreSettings with Native Format to read the windows registry in which the location of Office is stored. You can also get the version that way too if you wanted to show it to the user.

16th October 2009, 17:29
I am out of office for a few days, and I think read the windows registry may be is better, thank you , I will try!

17th October 2009, 15:38
Better than using QDesktopServices::openUrl()? I don't think so...

17th October 2009, 17:30
Most certainly, openUrl should work on Windows, Mac & Linux, whereas registry approach is Windows specific.

If you don't care your program is Windows specific, then can even use OLE:

Variant MSWord;
MSWord = CreateOleObject("Word.Basic");
MSWord.Exec(Procedure("FileNew") << "Normal");
MSWord.Exec(Procedure("Insert") << "Hello World!");

This way uses an existing instance if available, or loads the application if it's not already running.

7th September 2010, 15:33
Where can I find QCoreSettings? I have downloaded latest Qt open source and commercial versions (trial) but QCoreSettings is not there.

7th September 2010, 15:55
There is no such class in Qt. It's QSettings.