简体   繁体   English

如何在Qt GUI应用程序中附加MS Word文档?

[英]How to attach MS word document in Qt GUI application?

I wrote a Qt widget application. 我写了一个Qt小部件应用程序。 In the file menu I want to insert an MS word document as a user manual. 在文件菜单中,我要插入MS Word文档作为用户手册。 Is there any way to do it? 有什么办法吗? I checked Qt help and various blogs but none of them gave me a clear solution. 我检查了Qt帮助和各种博客,但没有一个给我明确的解决方案。

If it is only manual then it is not necessary to embed MS Word inside your app. 如果仅是手动操作,则无需在应用程序中嵌入MS Word Maybe try to open needed document with Word installed in computer. 也许尝试使用计算机中安装的Word打开所需的文档。 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 (ie, the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser. 如果URL是对本地文件的引用(即URL方案是“文件”),则将使用合适的应用程序而不是Web浏览器打开它。

If you want to embed it in your application executable, just insert your .docx file as a resource file. 如果要将其嵌入到应用程序可执行文件中,只需将.docx文件作为资源文件插入。 To open the docx file from resources, you should first copy it to some location for example in the application directory path : 要从资源打开docx文件,您应该首先将其复制到某个位置,例如在应用程序目录路径中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM