[Interest] resturn string to javascript inside QWebEngineView

Jason H jhihn at gmx.com
Wed Dec 12 22:55:20 CET 2018


I did this, in some abandoned work. Turns out QWebWhatever didn't do it right on iOS. It can't return a QVariantMap, you have to stringify it.

Timer {
		id: testTimer
		interval: 1000
		repeat:false
		running: false
		onTriggered: {
			webview.runJavaScript("try {testResult} catch (e) {'undefined'}", function (result) {
				console.log('object', JSON.stringify(result));
			});
			webview.runJavaScript("try {JSON.stringify(testResult)} catch (e) {'undefined'}", function (result) {
				console.log('stringified', JSON.stringify(result));
			});

		}
		onRunningChanged: console.log('running', running);
	}

	WebView {
		id: webview
		anchors.fill: parent
		onLoadProgressChanged: {
			console.log('loadProgress', loadProgress)
			if (loadProgress == 100) testTimer.running = true;
		}
	}


> Sent: Wednesday, December 12, 2018 at 3:46 PM
> From: roland at logikalsolutions.com
> To: interest at qt-project.org
> Subject: [Interest] resturn string to javascript inside QWebEngineView
>
> All,
> 
> Having a massive brain spasm today. Can't remember how to correctly  
> return a string from a function to javascript being run inside of  
> QWebEngineView via QWebChannel. Long ago when I first did this we used  
> QWebSockets but that had horrible nasty side effects and was banned  
> from the project during my absence. Cannot find a link how to do this  
> either.
> 
> It appears the real problem is Javascript isn't recognizing the  
> signature so refuses to call.



More information about the Interest mailing list