I wrote a Qt widget application. In the file menu I want to insert an MS word document as a user manual. Is there any way to do it? I checked Qt help and various blogs but none of them gave me a clear solution.
Asked
Active
Viewed 2,246 times
3
-
1Is there a particular reason to use MS Word document for the user manual? Why not to use plain text or html formats? – vahancho Dec 19 '14 at 12:39
-
@vahancho thanks for your reply. I already created a .doc manual with images and all stuff. So wanted to re use the content. Is there any way to embed .doc straight away? – Naveen kumar Katta rathanaiah Dec 19 '14 at 12:43
-
Qt supports embedding COM objects into widgets (see QAxObject manual), but the effort you will spend on this will be much more than simply conversion of your manual to any other "portable" format. – vahancho Dec 19 '14 at 12:50
-
2Why don't you export your document to pdf ? that is at least a little more portable than word and you can do it by a simple click in Word 2007+. Then you can use @Chernobyl answer and let the system figure out how to open the pdf document (shouldn't be a problem ...) – Félix Cantournet Dec 19 '14 at 13:10
2 Answers
3
If it is only manual then it is not necessary to embed MS Word
inside your app. Maybe try to open needed document with Word
installed in computer. Try this code:
QDesktopServices::openUrl(QUrl("file:///G:/tst.docx"));
Just set needed path. As doc said:
If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser.

Jablonski
- 18,083
- 2
- 46
- 47
-
Thank you @Chernobyl, it solved my problem with minimal effort :) – Naveen kumar Katta rathanaiah Dec 19 '14 at 15:16
1
If you want to embed it in your application executable, just insert your .docx file as a resource file. To open the docx file from resources, you should first copy it to some location for example in the application directory path :
QFile HelpFile("qrc:/myFile.docx");;
HelpFile.copy(qApp->applicationDirPath().append("/myFile.docx"));
Next you can open it by :
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath().append("/myFile.docx")));

Nejat
- 31,784
- 12
- 106
- 138
-
1Good way to reduce deployment pain. I'd use a temp path instead since you cannot expect that the user has write access to the application dir (e.g. Linux). – Simon Warta Dec 20 '14 at 12:44
-
@SimonWarta You are right. It's better to use a writable location by `QStandardPath`. – Nejat Dec 20 '14 at 13:01