[Interest] qtwebview with qtwebchannel

Artem Sidyakin artem.sidyakin at qt.io
Tue Sep 18 19:08:41 CEST 2018


Glad that you have succeeded.

Meanwhile, I’ve done some tests and most importantly finally read the documentation (https://doc.qt.io/qt-5.11/qml-qtwebview-webview.html#url-prop), so loading documents to WebView through qrc:/ is actually not supported. However, it does work on Mac OS :) but I guess we should consider this as an accident happy bonus.
The rest of usecases for qrc:/ work equally fine both on Mac OS and iOS (for example, setting source for Image).

---
Artem Sidyakin

> On 18 Sep 2018, at 00:02, Sylvain Pointeau <sylvain.pointeau at gmail.com> wrote:
> 
> Hello Artem,
> 
> it works! your code sample pointed me on the issue.
> 
> You were using "applicationDirPath", I was using QStandardPaths::writableLocation(QStandardPaths::TempLocation)
> 
> I tested applicationDirPath, same as you, it worked. (but this directory is not good because not writable.)
> then I tried  QString dataloc = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
> (Warning: you must create this directory!
>     QDir datadir(dataloc);
>     datadir.root().mkpath(dataloc);
> )
> and it also worked!!!
> 
> Thank you very much for helping me!!!
> 
> Best regards,
> Sylvain
> 
> On Sun, Sep 16, 2018 at 5:24 PM Artem Sidyakin <artem.sidyakin at qt.io> wrote:
> I would understand if local file loading was allowed and remote forbidden, but not the other way around. So if remote works, so should local.
> 
> To confirm that, I simply copied files into the app bundle (Show Package Contents) and just to be sure checked if they are “accessible”:
> 
> foreach(QString filename, QDir(app.applicationDirPath()).entryList()) {
>     qDebug() << “- " << filename;
> }
> 
> And they are, so I have the following files inside the app bundle:
> 
> websockets.app
> ├── _CodeSignature
> ├── bootstrap.min.css
> ├── Default-568h at 2x.png
> ├── embedded.mobileprovision
> ├── index.html
> ├── Info.plist
> ├── LaunchScreen.nib
> ├── META-INF
> ├── PkgInfo
> ├── qwebchannel.js
> └── websockets
> 
> Then I added applicationDirPath() as QML context property and loaded index.html into WebView like this:
> 
> url: “file:” + applicationDirPath + “/index.html”
> 
> And it works, so it doesn’t matter where the HTML document came from, would it be remote server or local file.
> 
> ---
> Artem Sidyakin
> 
> > On 16 Sep 2018, at 12:58, Sylvain Pointeau <sylvain.pointeau at gmail.com> wrote:
> > 
> > 
> > 
> > Le dim. 16 sept. 2018 à 12:22, Artem Sidyakin <artem.sidyakin at qt.io> a écrit :
> > 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.
> > 
> > ajax for instance does not work when the file is loaded from the filesystem. I suppose there is a limitation on the websocket accessing localhost. I also suppose this can be for security reason?
> > 
> > 
> > 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).
> > 
> > When I click on the button, nothing happens, and I suppose that qwebchannel.js is correctly loaded (it is in the same folder than the index.html)
> > 
> > 
> > 
> 



More information about the Interest mailing list