Results 1 to 2 of 2

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

  1. #1

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

    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++:

    Qt Code:
    1. page()->runJavaScript(js,[this](const QVariant &v) {
    2. qDebug()<<v.toString();
    3. }
    To copy to clipboard, switch view to plain text mode 

    js:

    Qt Code:
    1. var result="immature result";
    2. function fun()
    3. {
    4. result="mature result";
    5. }
    6. setTimeout(fun,2000);
    7. result;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    Your function will only be executed asynchronously after two seconds so the only option I see is to run another script afterwards and fetch the result. Or use QWebChannel as you have already stated yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. runJavascript result returned
    By Kasea in forum Qt Programming
    Replies: 7
    Last Post: 9th August 2017, 07:10
  2. [Qtwebengine] Running Chrome Apps in QtWebEngine
    By raunvivek in forum General Discussion
    Replies: 0
    Last Post: 9th July 2015, 13:32
  3. Replies: 3
    Last Post: 22nd March 2012, 21:08
  4. Debugging JavaScript code evaluated by QWebView
    By thiagoalencar22 in forum Newbie
    Replies: 0
    Last Post: 28th October 2009, 12:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.