PDA

View Full Version : QWebenginePage runJavascript callback not storing data in variable.



mvbhavsar
26th October 2020, 10:05
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


QString CodeMirror::text() const
{
QString v_data;
page()->runJavaScript("editor.getValue()",[this](const QVariant &v){
v_data = v.toString();
});
return v_data;
}


Please help me to resolve the same

Cheers

13565

d_stranz
26th October 2020, 16:40
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.

mvbhavsar
27th October 2020, 08:21
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

d_stranz
27th October 2020, 16:40
Hint: What did I say about capturing v_data?