[Qt-interest] How to load page from Qt resource with AJAX?
sherzod_
sherzod.l at mail.ru
Fri Nov 12 04:01:58 CET 2010
Hi, Girish
Excellent!)) Thank you, you pointed me the right way. Let me try to explain
why.
By webView.loadFromResource(":/root/index.html"); I meant something like
this:
//------------------------- c++ -------------------------------------
QResource page(":/elinksetup/index.html");
QString content = QString(QByteArray((const char*)page.data(),
page.size()));
QWebView webView.setHtml(content);
// this works, index.html is loaded, and I can see it :)
//-------------------------------------------------------------------
I can't remember why I did so. But after I changed it to
//------------------------- c++ -------------------------------------
QWebView webView;
webView.load(QUrl("qrc:/root/index.html"));
//-------------------------------------------------------------------
all stuff seems to work). So thank you again.
But I still wonder why in the first case AJAX doesn't work? Maybe something
wrong with baseUrl? The absolute path always used though... And the
LocalContentCanAccessRemoteUrls option is on. Well OK, maybe I should learn
about setHtml's specificity more.
> 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
>>
More information about the Qt-interest-old
mailing list