Results 1 to 4 of 4

Thread: QWebenginePage runJavascript callback not storing data in variable.

  1. #1
    Join Date
    Jun 2010
    Posts
    97
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QWebenginePage runJavascript callback not storing data in variable.

    Hi,

    I want to get data returned by Javascript into QT variable. Javascript is getting called successfully and also able to print output using qDebug(). However, I want to process the output and hence needs to be stored in one variable. But it is giving error either no viable overload '=' or variable 'v_data' cannot be implicitly captured in a lambda with no capture-default specified

    I have below code
    Qt Code:
    1. QString CodeMirror::text() const
    2. {
    3. QString v_data;
    4. page()->runJavaScript("editor.getValue()",[this](const QVariant &v){
    5. v_data = v.toString();
    6. });
    7. return v_data;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Please help me to resolve the same

    Cheers

    Screenshot 2020-10-26 at 3.28.30 PM.jpg

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWebenginePage runJavascript callback not storing data in variable.

    If your intent is to store the result of the javascript call into the QVariant v, then why are you declaring it as a const reference in your lambda? In addition, the local QString variable v_data is not a member variable of CodeMirror, so capturing "this" does not capture v_data.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2010
    Posts
    97
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebenginePage runJavascript callback not storing data in variable.

    Thanks for reply.
    Can you please suggest change in the code. Removing const lambda reference is also not working. Simple requirement is to get Javascript output coming from HTML page to be captured i

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWebenginePage runJavascript callback not storing data in variable.

    Hint: What did I say about capturing v_data?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Storing lots of data.
    By Granum in forum Newbie
    Replies: 2
    Last Post: 26th April 2017, 17:42
  2. Replies: 7
    Last Post: 2nd April 2015, 21:48
  3. Problem in storing hex data to char variable
    By prasad1001 in forum Newbie
    Replies: 1
    Last Post: 7th April 2014, 08:16
  4. Data Reading and Storing in arrays
    By kango in forum Newbie
    Replies: 8
    Last Post: 6th January 2013, 16:13
  5. Saving and storing data,QtSql
    By salmanmanekia in forum Newbie
    Replies: 7
    Last Post: 20th April 2010, 20:08

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.