QWebEngineView runJavaScript() problem

  • Hello all.

    I faced with some strange behavior in QWebEngineView.
    I have a loaded page in QWebEngineView object witch has 'group0' element.
    I run next script:

    QString script = "document.getElementsByName('group0');";
    page()->runJavaScript(script, [](const QVariant &v) {qDebug() << v;});

    It prints

    QVariant(QVariantMap, QMap())

    But now I need value of first element of 'group0' (or array with several values). I tried to run script:

    QString script = "var elems=document.getElementsByName('group0');" 
    page()->runJavaScript(script, [](const QVariant &v) {qDebug() << v;});

    But I got


    Documentation says

    Runs the JavaScript code contained in scriptSource.
    When the script has been executed, resultCallback is called with the result of the last executed statement.
    Note: resultCallback can be any of a function pointer, a functor or a lambda, and it is expected to take a QVariant parameter.

    Could you say me how can I return result of the last executed statement from script to callback.

    Thank you.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.