Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Why I get two <loadFinished> signal sometimes?
Forum Updated to NodeBB v4.3 + New Features

Why I get two <loadFinished> signal sometimes?

Scheduled Pinned Locked Moved Solved QtWebEngine
6 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QBoy
    wrote on last edited by QBoy
    #1

    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.

    Q 1 Reply Last reply
    0
    • Q QBoy

      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.

      Q Offline
      Q Offline
      QBoy
      wrote on last edited by QBoy
      #2

      @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!

      呵呵呵.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Lankin
          wrote on last edited by
          #4

          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

          Q 1 Reply Last reply
          0
          • L Lankin

            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

            Q Offline
            Q Offline
            QBoy
            wrote on last edited by
            #5

            @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.

            L 1 Reply Last reply
            0
            • Q QBoy

              @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.

              L Offline
              L Offline
              Lankin
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved