[Development] Qt WebChannel 5.5 roadmap: WebEngine, QtWebView

Sorvig Morten Morten.Sorvig at digia.com
Wed Aug 27 21:42:02 CEST 2014


> On 27 Aug 2014, at 16:51, Milian Wolff <milian.wolff at kdab.com> wrote:
> 
> On Wednesday 27 August 2014 14:49:08 Hausmann Simon wrote:
>> I'm pretty sure that all the "native" webview APIs allow for at least
>> runJavascript(string), so injection may also be an easier option.
> 
> Oh nice, I assumed without testing nor reading code that the QtWebView API 
> would be very minimal and thus not even supply such an API. If it does exist 
> then yes, I think just injecting the qwebchannel.js contents and a simple 
> schim to setup the WebSocket would be best.

It’s not there today but I think we could add it. The function is useful for extending QtWebView beyond the current API.

What should the function signature be? Looking at the existing classes:

UIWebView:
	 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script .

WKWebView:
	- (void) evaluateJavaScript:(NSString *) javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler; 

android.webkit.WebView:
	void evaluateJavascript(String script, ValueCallback<String> resultCallback)

QWebEnginePage:
	void runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback);

API Options:

void runJavascript(const QString &script)	// asynchronous if possible
QString runJavascript(const QString &script) // synchronous
template <typename C> void runJavascript(const QString &script, C callback) // Use a C++11 lambda function

I think I would like to avoid adding a callback-class based API, let’s go for a more modern variant. Returning a result makes the function more useful, but with a simple function this comes at the cost of making it synchronous. UIWebView does not seem to support asynchornous evaluation in any case, but we can live with that until WKWebView is available (which is iOS8, OS X10.10).

Morten





More information about the Development mailing list