[Development] [Interest] qtwebview with qtwebchannel

Sylvain Pointeau sylvain.pointeau at gmail.com
Sat Sep 15 10:21:11 CEST 2018


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); }
>
>                 }
>
>             }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180915/6ae4abca/attachment.html>


More information about the Development mailing list