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. How to get result from javascript code run by runJavaScript in QtWebengine?

How to get result from javascript code run by runJavaScript in QtWebengine?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 3 Posters 3.5k Views
  • 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.
  • Y Offline
    Y Offline
    yetanotherqtfan
    wrote on 21 Jul 2019, 09:20 last edited by
    #1

    How can I get the result from javascript run by runJavaScript in QtWebengine?

    I want to get result from the js run by runJavaScript. The result is formed after some time in js, but since js returns immediately, I can not get the mature result. How can I modify the js code or the C++ code to get the mature result? I know I can use QWebChannel to notify C++ of the mature result at appropriate time but that is a little complex. Can I delay the return time of js code so it can return with the matured result?

    C++:

    page()->runJavaScript(js,[this](const QVariant &v) {
            qDebug()<<v.toString();
    }
    

    js:

    var result="immature result";
    function fun()
    {
        result="mature result";
    }
    setTimeout(fun,2000);
    result;
    
    J 1 Reply Last reply 22 Jul 2019, 11:36
    0
    • Y yetanotherqtfan
      21 Jul 2019, 09:20

      How can I get the result from javascript run by runJavaScript in QtWebengine?

      I want to get result from the js run by runJavaScript. The result is formed after some time in js, but since js returns immediately, I can not get the mature result. How can I modify the js code or the C++ code to get the mature result? I know I can use QWebChannel to notify C++ of the mature result at appropriate time but that is a little complex. Can I delay the return time of js code so it can return with the matured result?

      C++:

      page()->runJavaScript(js,[this](const QVariant &v) {
              qDebug()<<v.toString();
      }
      

      js:

      var result="immature result";
      function fun()
      {
          result="mature result";
      }
      setTimeout(fun,2000);
      result;
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Jul 2019, 11:36 last edited by
      #2

      @yetanotherqtfan https://doc.qt.io/qt-5/qwebenginepage.html#runJavaScript-2

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • H Offline
        H Offline
        Hetal
        wrote on 4 Sept 2019, 06:18 last edited by Hetal 9 Apr 2019, 06:18
        #3

        In your runJavascript function either you emit a signal or you can call a function of the save class and then pass the value in that function.

        page()->runJavaScript(js,[this](const QVariant &v) {
        newFunction(v);
        }

        Then in newFunction you can carry out the further code.

        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