Signal QWebPage::loadFinished(bool) returns twice?

戏子无情 提交于 2019-12-13 19:08:34

问题


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 ?

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;
            }
        }
};

回答1:


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.



来源:https://stackoverflow.com/questions/8415289/signal-qwebpageloadfinishedbool-returns-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!