将Web应用程序作为资源嵌入到C ++ Qt可执行文件中 [英] Embed web application as a resource into C++ Qt executable

查看:358
本文介绍了将Web应用程序作为资源嵌入到C ++ Qt可执行文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 QWebView 中加载一种网络应用程序。

I would like to load a sort of "web application" in a QWebView.

我的网页应用程序由一些带有CSS,Javascript和图片的HTML5页面组成。它是完全自主的。它不需要服务器。

My "web application" is made up of some HTML5 pages with CSS, Javascript and pictures. It is totally autonomous. It does not need a server.

我对Qt编程很新。有没有办法将这些文件嵌入到Qt项目中,并在程序启动时将它们加载到 QWebView 中?

I am quite new to Qt programming. Is there a way to embed those files into the Qt project and load them in the QWebView when the program starts?

我已经设法从远程HTTP服务器加载这些页面,但我的应用程序必须是独立的。

I already managed to load those pages from a remote HTTP server but my application must be standalone.

编辑

感谢您的解决方案Yodabox。页面显示良好。我将baseUrl设置为qrc:/// web /而不是:/ web /。但我仍有问题。

Thank you for your solution Yodabox. The page is well displayed. I set baseUrl as "qrc:///web/" instead of ":/web/". But I still have a problem.

我对嵌入式XML文件执行异步请求以在HTML选择中加载值。 JavascriptConsole提供消息: XHR已完成加载:qrc:///web/xml/values.xml 但未填充选择 。你有什么解决方案吗?

I do an async request to an embedded XML file to load values in an HTML select. The JavascriptConsole gives the message: XHR finished loading: "qrc:///web/xml/values.xml" but the select is not populated. Do you have any solution?

推荐答案

你需要的只是 QWebView :: setHtml

void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )

你应该将baseUrl设置为:/ web /并将html设置为HTML文件内容,请阅读Qt DOC以获取详细信息。

you should set baseUrl as ":/web/" and html as the HTML file content,please read Qt DOC for detail.

这篇关于将Web应用程序作为资源嵌入到C ++ Qt可执行文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆