How to call WinWord.exe through the Qt program?
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!
Code:
lst.append(tr("E:/test.doc"));
por->start(tr("WinWord.exe"),lst);
Re: How to call WinWord.exe through the Qt program?
what for are you use QObject::tr() function?
Re: How to call WinWord.exe through the Qt program?
and if you write simply WinWord.exe the path that contains this file(WinWord.exe) must be add in a system path.
Re: How to call WinWord.exe through the Qt program?
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.
Re: How to call WinWord.exe through the Qt program?
Quote:
Originally Posted by
bangqianchen
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...)
Re: How to call WinWord.exe through the Qt program?
Re: How to call WinWord.exe through the Qt program?
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.
Re: How to call WinWord.exe through the Qt program?
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!
Re: How to call WinWord.exe through the Qt program?
Better than using QDesktopServices::openUrl()? I don't think so...
Re: How to call WinWord.exe through the Qt program?
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("AppShow"));
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.
Re: How to call WinWord.exe through the Qt program? [where is QCoreSettings?]
Where can I find QCoreSettings? I have downloaded latest Qt open source and commercial versions (trial) but QCoreSettings is not there.
Re: How to call WinWord.exe through the Qt program? [where is QCoreSettings?]
There is no such class in Qt. It's QSettings.