¿Cómo puede Qt usar WebBrowser y llamar a funciones JS en páginas web?
Se recomienda configurarlo dinámicamente en el código, por ejemplo. ejemplo
[cpp] ver copia simple
ui->axWidget->.setControl("Shell.Explorer"); DynamicCall("Navigate(QString)", "C :/1.html");
Por supuesto, el "C:/1.html" anterior es mi página de prueba
El método aquí se ejecuta a través del método execScript de las funciones JavaScript de la interfaz IHTMLWindow2. Lamentablemente, este método no admite valores de retorno de funciones
[cpp] Ver texto sin formato
#include
{
QAxObject *document = ui->axWidget->.querySubObject("Documento");
IHTMLDocument2 *doc2
documento->queryInterface(QUuid(IID_IHTMLDocument2), ( void; **)&.doc2);
if (doc2)
{
IHTMLWindow2 *win2 = nullptr; ->get_parentWindow(&win2) == S_OK)
{
BSTR s1 = SysAllocString(L "Test()");
BSTR s2 = SysAllocString ( L "JavaScript");
VARIANT ret;
win2->execScript(s1, s2, &ret); ) == S_OK)
{ amp;ret);
SysFreeString(s2);
SysFreeString(s1);
}
}
La función de JavaScript es la siguiente
[html] Ver texto sin formato
< script language ="javascript" type="text/javascript">
function Test()
{
alert("Has llamado a la función global Prueba" );
}