Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't actually done this, but I think you <em>may</em> be able to achieve your solution using <code>QNetworkAccessManager</code>.</p> <p>You can get the QNetworkAccessManager from your QWebPage using the <a href="http://doc.trolltech.com/4.5/qwebpage.html#networkAccessManager" rel="noreferrer">networkAccessManager()</a> function. QNetworkAccessManager has a signal <a href="http://doc.trolltech.com/4.5/qnetworkaccessmanager.html#finished" rel="noreferrer">finished ( QNetworkReply * reply )</a> which is fired whenever a file is requested by the QWebPage instance.</p> <p>The <code>finished</code> signal gives you a QNetworkReply instance, from which you can get a copy of the original request made, in order to identify the request.</p> <p>So, create a slot to attach to the <code>finished</code> signal, use the passed-in QNetworkReply's methods to figure out which file has just finished downloading and if it's your Ajax request, do whatever processing you need to do.</p> <p>My only caveat is that I've never done this before, so I'm not 100% sure that it would work.</p> <p>Another alternative might be to use QWebFrame's methods to insert objects into the page's object model and also insert some JavaScript which then notifies your object when the Ajax request is complete. This is a slightly hackier way of doing it, but should definitely work.</p> <p>EDIT:</p> <p>The second option seems better to me. The workflow is as follows:</p> <p>Attach a slot to the QWebFrame::javascriptWindowObjectCleared() signal. At this point, call QWebFrame::evaluateJavascript() to add code similar to the following: window.onload = function() { // page has fully loaded }</p> <p>Put whatever code you need in that function. You might want to add a QObject to the page via QWebFrame::addToJavaScriptWindowObject() and then call a function on that object. This code will only execute when the page is fully loaded.</p> <p>Hopefully this answers the question!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload