[Development] [Interest] qtwebview with qtwebchannel

Artem Sidyakin artem.sidyakin at qt.io
Sat Sep 15 23:21:35 CEST 2018


> I hadn’t heard about this change and old habits die hard

I can certainly double that! Good news.

> Are you sure the WebView can load from the resources (url: “qrc:/index.html)?

I knew it cannot (does qrc:/ work on iOS at all?), but I was silently waiting for someone to provide the way it should be done on iOS :)
Unfortunately no-one did, so apparently it’s a bigger problem than I thought.
And what I did - just served index.html and qwebchannel.js via regular webserver (lighttpd) from my machine.

> @qt developers, please could you confirm if the webchannel is working or not on ipad (with the webview)?

Having learned that I actually can deploy to physical devices without paying 99 USD to Apple (thank you for the link), I tried it with my iPhone, and it works there: https://goo.gl/uQp8fR (alerts do not work, I guess it’s iOS restriction, but QML label changes its text as it should).
So I can confirm that WebChannel over WebSocket communication does work with WebView on iOS.

---
Artem Sidyakin

> On 15 Sep 2018, at 10:21, Sylvain Pointeau <sylvain.pointeau at gmail.com> wrote:
> 
> to make it clearer, it does work on the simulator but not on my ipad device.
> @qt developers, please could you confirm if the webchannel is working or not on ipad (with the webview) ?
> 
> Le ven. 14 sept. 2018 à 22:43, Sylvain Pointeau <sylvain.pointeau at gmail.com> a écrit :
> Hello,
> 
> I finally succeeded to make it working on the simulator... unfortunately it does not work on the physical ipad.
> 
> to make it working, I had to copy the resource files on the temp dir, to pass the temp dir to QML, then use "file://"+mytemppath+"/index.html". Also I removed all "qrc:/" in the html, and put manually the qwebchannel.js in the qrc.
> 
>     QString tmploc = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
>     QDir tmpdir(tmploc+"/");
> 
>     qDebug() << QFileInfo(tmpdir.absolutePath()).absoluteFilePath();
> 
>     QDirIterator it(":"/*, QDirIterator::Subdirectories*/);
>     while (it.hasNext()) {
>         QString tmpfile = it.next();
>         QFileInfo file = QFileInfo(tmpdir.absolutePath() + tmpfile.right(tmpfile.size()-1));
>         QFile::remove(file.absoluteFilePath()); // remove previous file to make sure we have the latest version
>         QFile::copy(tmpfile, file.absoluteFilePath());
>         qDebug() << tmpfile;
>     }
> 
> .....
> 
>     QQmlApplicationEngine engine;
> 
>     QQmlContext *context = engine.rootContext();
>     context->setContextProperty(QStringLiteral("mylocalpath"), QFileInfo(tmpdir.absolutePath()).absoluteFilePath());
> 
> .....
> 
> and in QML:
> 
>             WebView {
>                 id: webView
>                 anchors.fill: parent
>                 anchors.margins: 5
>                 url: "file://"+mylocalpath+"/index.html"
>                 onLoadingChanged: {
>                     if (loadRequest.errorString)
>                         { console.error(loadRequest.errorString); }
>                 }
>             }



More information about the Development mailing list