如何知道当一个网页使用QtWebKit的时候装? [英] How to know when a web page is loaded when using QtWebKit?

查看:366
本文介绍了如何知道当一个网页使用QtWebKit的时候装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个 QWebFrame QWebPage 无效loadFinished(布尔OK)信号可被用来检测一个网页完全装满。问题是,当一个网页有异步加载一些内容(AJAX)。如何知道什么时候该页面完全在这种情况下,装?

Both QWebFrame and QWebPage have void loadFinished(bool ok) signal which can be used to detect when a web page is completely loaded. The problem is when a web page has some content loaded asynchronously (ajax). How to know when the page is completely loaded in this case?

推荐答案

我还没有真正做到这一点,但我觉得你的可以的能够使用来实现您的解决方案 QNetworkAccessManager

I haven't actually done this, but I think you may be able to achieve your solution using QNetworkAccessManager.

您可以从您的QWebPage使用 networkAccessManager()函数得到QNetworkAccessManager。 QNetworkAccessManager具有信号完成(QNetworkReply *回复)当文件要求的QWebPage实例,它是发射

You can get the QNetworkAccessManager from your QWebPage using the networkAccessManager() function. QNetworkAccessManager has a signal finished ( QNetworkReply * reply ) which is fired whenever a file is requested by the QWebPage instance.

完成信号给你一个QNetworkReply实例,从中可以得到所取得的原始请求的副本,以识别请求。

The finished signal gives you a QNetworkReply instance, from which you can get a copy of the original request made, in order to identify the request.

因此​​,创建一个插槽连接到完成信号,使用传入的QNetworkReply的方法来找出哪个文件刚刚完成下载,如果这是你的Ajax请求,做任何处理,你需要做的。

So, create a slot to attach to the finished 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.

我唯一需要注意的是,我从来没有这样做过,所以我不是100%肯定它会工作。

My only caveat is that I've never done this before, so I'm not 100% sure that it would work.

另一种方法是使用QWebFrame的方法将对象插入页面的对象模型,并插入一些JavaScript,然后通知你的对象时,Ajax请求完成。这是做的稍微hackier方式,但一定要努力。

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.

编辑:

第二个选择似乎不如我。的工作流程如下:

The second option seems better to me. The workflow is as follows:

附加槽到QWebFrame :: javascriptWindowObjectCleared()信号。在这一点上,调用QWebFrame :: evaluateJavascript()增加code类似以下内容:     在window.onload =功能(){//页面完全加载}

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 }

放置任何code,你需要该功能。你可能想通过QWebFrame :: addToJavaScriptWindowObject()一个QObject添加到页面中,然后调用该对象的功能。当页面完全加载此code将只执行。

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.

希望这回答了这个问题!

Hopefully this answers the question!

这篇关于如何知道当一个网页使用QtWebKit的时候装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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