[Development] [Interest] qtwebview with qtwebchannel

Sylvain Pointeau sylvain.pointeau at gmail.com
Tue Sep 18 00:02:38 CEST 2018


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)
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180918/9b48cc9a/attachment.html>


More information about the Development mailing list