Why I get two <loadFinished> signal sometimes?



  • hello everyone.

    I want to run some javascript when page finish loading. But when debugging, I find that the <loadFinished>'s slot is invoked twice sometimes. Of course not all site i visit is the same.

    here is the console message:
    0_1473320656688_2016-09-08_154344.png

    I think the main reason should be the problem of the website, could be coused by ajax or frame?

    You can try to visit "www.baidu.com" and search something, when opening new page, the slot is invoked, when loading is finished, slot is invoed again. but if i refresh the new page, there is the only one <loadFinished> signal.

    I just want to wait for page to finsh loading, then i run javascript. Is there any other solutions?

    $(document).ready(); is not work well...

    Thank you in advance.



  • @QBoy Finally i find something.
    here is the content of page when the first signal <loadFinished> was emited.
    0_1473324361298_2016-09-08_164541.png

    here is the content of page when the second signal <loadFinished> was emited.
    0_1473324835483_2016-09-08_164814.png

    The image illustrate that when load new page, the WebEngine construct a new simple page first, which has a "Refresh" attribute. then "refresh" action triggered. But When I test other site, there is No such situation. In a conclusion, the problem is caused by website's behavior. if website decide to use ajax to load content, when you click the link in this page, the signal <loadFinished> will be not emited. The signal <loadFinised> is NO problem!

    呵呵呵.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The upload function of the forum is currently broken. Can you use an other image upload site so we can see them ?



  • When the dom changed or reloaded, or click herf, the loadFinished signal emited. I user a variable value to record the load status.such as:
    if (m_bLoadIndexSucced)
    {
    return;
    }
    m_bLoadIndexSucced = true;
    //write you code



  • @Lankin Thanks, but How to make sure that when the first signal <loadFinished> is emitted, the page is really & totally loaded? Is this could be a potential problem?

    Besides, I found that if i call "runJavaScript", and passed a string which contains "console.log('just infomation')", two messages were printed out. It made me confused and i started to think that the function "runJavascript" run the javascript code we passed to it twice!! Finally, I found that only the function of object "console" would be run twice or more precisely, message would be print twice.



  • @QBoy said in Why I get two <loadFinished> signal sometimes?:

    potential

    You can runJavaScript after the first <loadFinished> signal emitted.
    you can construct new QWebChannel in js file when $(document).ready().
    js can invoke c++ method when construct the QWebChannel finished.
    I use Qt5.4(webView)、Qt5.6(webEngineView)、Qt5.7, the js just run once.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.