[Development] [Interest] qtwebview with qtwebchannel

Artem Sidyakin artem.sidyakin at qt.io
Sun Sep 16 12:22:25 CEST 2018


Original question was about “communication between WebView and QML on iOS”, which does work, as we can see.
Now there is an issue of loading HTML documents from file/resource system, but that’s a different kind of issue, innit (which I also would like to get to the bottom of).

> you confirm that the webchannel is working if the page is loaded from a server

Indeed, but what difference does it make? After the page is downloaded from the server it is run locally in the WebView on device.

Now, when you say

> unfortunately it does not work on the physical ipad

how exactly it does not work? Page is not loaded in the WebView? Or it is loaded (input field and button), but when you click the button nothing happens? If it’s the latter, then I would guess that qwebchannel.js is not loaded properly (wrong path, etc).

---
Artem Sidyakin

> On 16 Sep 2018, at 11:49, Sylvain Pointeau <sylvain.pointeau at gmail.com> wrote:
> 
> 
> > 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
> 
> OK, now I understand why I do have a different result than you.
> The use case is then different, I would not expect an app to run HTML from a server but embedded into the app itself. Additionally I gave the solution how to extract the HTML into the local folder and load from there.
> 
> >     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;
> >     }
> > .....
> >     QQmlContext *context = engine.rootContext();
> >     context->setContextProperty(QStringLiteral("mylocalpath"), QFileInfo(tmpdir.absolutePath()).absoluteFilePath());
> 
> > @qt developers, please could you confirm if the webchannel is working or not on ipad (with the webview)?
> 
> So I can confirm that WebChannel over WebSocket communication does work with WebView on iOS.
> 
> More precisely, you confirm that the webchannel is working if the page is loaded from a server.
> and I confirm that it does not work if the page is loaded from the filesystem.
> 
> It is a terrible news for me, there are so many use cases where I need to run HTML pages which are downloaded or created by the app. I need to be able to communicate between the HTML and the backend, to store values locally and provide content.
> 
> 
> 
>  



More information about the Development mailing list