Hi,

We have a Qt Web Application, where the first page is loaded by Qt C++, and then the page navigation is entirely handled by javascript.
We have a new use case, where the Page need to be reloaded when the language is modified. But the language callback is implemented in C++ code.

We wanted to invoke an JS event from C++ code, when the language is modified with the current language as argument.

Also using evaluateJavaScript, we are unable to access document.element values. Test Code given below:

Pasting the sample code that we are using to trigger the event:

{
QApplication a(argc, argv);

QMainWindow *TestQtWebClass = new QMainWindow();
QRect rect(0,0,640, 480);
TestQtWebClass->setGeometry(rect);
TestQtWebClass->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
QWidget *centralWidget = new QWidget(TestQtWebClass);
QWebView *webView = new QWebView(centralWidget);
QWebPage *testPage = new QWebPage(webView);
webView->setPage(testPage);
QWebPage *testWebPage = webView->page();

QWebSettings::globalSettings()->setAttribute(QWebSettings::developerExtrasEnabled , true);
testWebPage->mainFrame()->setUrl(QUrl(QStringLiteral("file:///usr/web/test.html")));

TestQtWebClass->setCentralWidget(centralWidget);


QWebFrame *frame = webView->page()->mainFrame();
TestQtWebClass->show();
QVariant res1 = testWebPage->mainFrame()->evaluateJavaScript(QString("document.getElementBy Id("custId").value;"));
qDebug() << res1.toString(); Note: Prints "" instead of 3487

testWebPage->mainFrame()->evaluateJavaScript("alert("Calling JS function")"); Note: Only this works

return a.exec();
}

test.html referenced in the code is given below:


<html><head>
<link id="id_css" rel="stylesheet" href=""/>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function init()
{
alert("page load completed");
}

function DDU_DAS_OnClick()
{
alert("Clicked1");
}

function myFunction() {
alert("onchange");
}

</script>
</head>
<BODY onload="init()" style="overflow: hidden;color: black; background-color: #000000" draggable="false" ondragstart="return false;">
<TEXTAREA ID="GfxInputDas63167771" onclick="DDU_DAS_OnClick(this)" data-Origin="DAS" data-VKEnabled=True data-VkMaxCharacters=80 data-VkTitle="Title" data-Variable=LB_RPT_TITLE data-TextDecoration="normal" data-FontColor="#ffffff" data-FontFamily="Arial" data-FontSize="10pt" data-FontStyle="normal" data-FontWeight="normal" style="text-decoration: normal;font-weight: normal;font-style: normal;text-align: left;font-family: Arial;font-size: 10pt;color: #ffffff;z-index: 1;position: absolute;top: 57;left: 166;width: 412;height: 21;background-color: #000000;opacity: 1;border: 1px solid #ff0000;visibility: visible;resize: none"></TEXTAREA>
<INPUT type="hidden" onchange="myFunction()" id="custId" name="custId" value="3487">
</DIV>
</BODY></html>


Request your suggestion,

Thanks,