Search code examples
c++qtqwebengineview

Auto-filling the HTML input field with a C++ QString value


I am finding the 'Sign in' text on the QWebEnginePage and then auto filling in the emailId in the input field if the correct page is displayed. The value of emailId is basically a QString.

QString emailId = "[email protected]";

What I have uptil now is the following, when the correct page is loaded, the input field is traced but the actual issue is setting the value = [email protected]. Is there a way to set value of the input to be equal to the QString value. (I do not want to hardcode the value).

ui->webEngineView->page()->findText(QStringLiteral("Sign in"), QWebEnginePage::FindFlags(), [this](bool found) {
    if (found) {
       QString code =  QStringLiteral("document.querySelectorAll('input')[0].value = emailId");
       ui->webEngineView->page()->runJavaScript(code);
    }
});

Solution

  • According to @eyllanesc's comment the following worked for me:

    QString code =  QString("document.querySelectorAll('input')[0].value = '%1'").arg(emailId);