From f785d81c41fc346465b3cf7a65097742b04a9ddf Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 4 Nov 2016 10:59:28 +0100 Subject: [PATCH] Fix creating QWebChannel on first QWebEnginePage load The "qt" object may be undefined at the time QWebEngineScript that creates web channel is being run. Try to create the web channel until it finally succeeds in 100ms intervals. Fixes the "Uncaught ReferenceError: qt is not defined" error message. --- src/lib/tools/scripts.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/tools/scripts.cpp b/src/lib/tools/scripts.cpp index fafff618c..586ece4b9 100644 --- a/src/lib/tools/scripts.cpp +++ b/src/lib/tools/scripts.cpp @@ -45,9 +45,16 @@ QString Scripts::setupWebChannel() " return;" "}" "" - "new QWebChannel(qt.webChannelTransport, function(channel) {" - " registerExternal(channel.objects.qz_object);" - "});" + "function registerWebChannel() {" + " try {" + " new QWebChannel(qt.webChannelTransport, function(channel) {" + " registerExternal(channel.objects.qz_object);" + " });" + " } catch (e) {" + " setTimeout(registerWebChannel, 100);" + " }" + "}" + "registerWebChannel();" "" "})()");