[Qt-interest] How to load page from Qt resource with AJAX?
Girish Ramakrishnan
girish at forwardbias.in
Thu Nov 11 20:02:32 CET 2010
Hi Sherzod,
What does webView.loadFromResource(":/root/index.html"); do? QWebView has no
such method.
qrc:/root/index.html and qrc:/root/sayHello.html is the correct way to
address the resources.
What you are doing below should work. All network requests go through QNAM
and the file backend supports qrc: scheme. I can give you a few debugging
hints:
0. Does webView.load("qrc:/root/index.html") load index.html? If not you
might need a Q_INIT_RESOURCE in your main app. Since the resource is in a
dll and the dll maybe dynamically initialized, the resources are probably
not registered wit Qt yet. Does it work if you move the resource files to
the main application?
1. If index.html loads, then you should be able to issue a request
as .load("sayHello.html");. This will at least eliminate the cross-origin
request scenario.
Girish
On Thu, Nov 11, 2010 at 2:20 PM, sherzod_ <sherzod.l at mail.ru> wrote:
> Hello.
>
> Let us have a resource "qrc:/root/sayHello.html" with a simple content
> <p>Hello, world!</p>.
>
> I need to load the content of the resource to some <div> element by means
> of
> ajax, wich runs in a context of some other page in a QWebView.
>
> ---------------------------------------------------------------
>
> <!-- qrc:/root/sayHello.html -->
> <p>Hello, world!!!</p>
>
> ---------------------------------------------------------------
>
> <!-- qrc:/root/index.html -->
> <!DOCTYPE somekindofhtml>
> <html>
>
> <script type="text/javascript">
> /* use JQuery */
> $(document).ready(function (){
> $("#board")
> /* this doesn't work */
> .load("qrc:/root/sayHello.html");
> });
> </script>
>
> <body>
> <div id="board"></div>
> </body>
> </html>
>
> ---------------------------------------------------------------
> // c++ code
> QWebView webView;
> webView.loadFromResource(":/root/index.html"); // Let it be
>
>
> extra:
> tried all combinations of qrc, :, /, //, ///
> resource is in dll wich i d-ly load at runtime via plugin api
>
> How to do it correct?
> i'll be glad to any suggestions.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101112/cc869742/attachment.html
More information about the Qt-interest-old
mailing list