问题描述
我遇到了 QWebPage::loadFinished (bool) 信号的问题,它回调了两次,这正常吗?(根本没有链接,例如 HTTP 状态 302)
I got a problem with QWebPage::loadFinished (bool) signal , it calls back twice , is that normal ? ( there's no link following at all , e.g HTTP status 302 )
考虑下面的代码,整个事情可能会导致问题,正在尝试加载该插槽内的另一个链接,这会是一个问题吗?
Consider the following code , the whole thing may cause problem , is trying to load another link within that slot , will this be a problem ?
如果我执行 qDebug() < 每次在
loadFinished(bool)
槽中,我都能看到 3 次,正常吗,url XXX
1 次,url 2 次YYY
,最后两个链接完全一样.
If i do a qDebug() << thisUrl;
each time in loadFinished(bool)
slot , i could see it for 3 times , is that normal , one for url XXX
, and two for url YYY
, and the last two links are exactly the same.
class Dummy
{
public:
Dummy()
{
page = new QWebPage(this);
connect (page , SIGNAL(loadFinished(bool)) , SLOT(loadFinished(bool)));
page->mainFrame()->load ("XXX");
}
private:
QWebPage *page;
private slots:
void loadFinished (bool ok)
{
if ( ! ok ) return;
const QString & thisUrl = page->mainFrame()->url().toString();
if ( thisUrl matches XXX )
{
// parse reply message of url XXX
page->mainFrame()->load ("YYY");
return;
}
if ( thisUrl matches YYY )
{
// parse reply message of url YYY
return;
}
}
};
推荐答案
我在 qt 4.7.4(使用 phantomjs)中也看到了这一点.我使用了框架的 loadFinished 而不是页面的,它没有发送两次.
im seeing this too with qt 4.7.4 (with phantomjs). i used the frame's loadFinished instead of the page's and it isn't sent twice.
这篇关于信号 QWebPage::loadFinished(bool) 返回两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!