QWebView evaluatejavascript argument
-
wrote on 26 Jun 2013, 01:07 last edited by
Hello,
When using the evaluateJavaScript("someMethod()") in a QWebView, is it possible to use a callback instead of typing the method itself?
Ex.
On Qt:
@
void getMessage(const QString &callback) {
(...).evaluateJavaScript(callback(arg1, ...);
}
@The callback function would be one within a js file, ex.:
@
function hello(arg1) {
alert(arg1);
}
@The call in the HTML file would be:
@
*something.getMessage(hello);
@As you see, the function called in the HTML file points the callback to the function Hello, but its arguments would come from Qt.
I have to use callback instead of typing the method itself. Any tips?
Thanks!
-
wrote on 26 Jun 2013, 06:20 last edited by
looks more like a javascript problem and I think, there are no callbacks in Javascript.
-
since evaluateJavaScript() only takes 1 string as an argument how would that be possible?
But if it helps you can compose javascript inside javascript and execute it using "eval(...)":http://www.w3schools.com/jsref/jsref_eval.asp
-
wrote on 26 Jun 2013, 11:02 last edited by
Hum?
I don't think you got it:
@
void Container::getEventInformation(const QString &eventId, const QString &callback)
{
// What it is now
view->page()->mainFrame()->evaluateJavaScript(QString("eventResult('%1','%2')").arg(eventId).arg(eventId));// What I need: evaluate the callback function
// view->page()->mainFrame()->evaluateJavaScript(callback('%1','%2')).arg(x).arg(y));
}
@To remember, callback is a javascript function.
But, it does not work. The evaluateJavaScript (callback) does not execute the callback function. So, is there a way to make it work?
1/4