[Interest] qtwebview with qtwebchannel

Sylvain Pointeau sylvain.pointeau at gmail.com
Fri Sep 14 22:43:16 CEST 2018


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); }

                }

            }





On Fri, Sep 14, 2018 at 9:27 PM Sylvain Pointeau <sylvain.pointeau at gmail.com>
wrote:

> I did copy the file on a writeable path, it does not load neither... does
> it even load local files, located in the app document folder?
>
> On Fri, Sep 14, 2018 at 8:44 PM Sylvain Pointeau <
> sylvain.pointeau at gmail.com> wrote:
>
>> Are you sure the WebView can load from the resources (url:
>> "qrc:/index.html)?
>> for me this does not work on ios, how could you make it run?
>>
>> Best regards,
>> Sylvain
>>
>> On Fri, Sep 14, 2018 at 7:48 PM Sylvain Pointeau <
>> sylvain.pointeau at gmail.com> wrote:
>>
>>> Hi Artem,
>>>
>>> I just tried yesterday and today evening.
>>> For me it does work on the desktop but not on the simulator. (the screen
>>> has 2 rectangles, one green with the text "some text" and one empty blue
>>> box)
>>>
>>> I have Qt 5.11.1
>>>
>>> not sure what happens...
>>>
>>> Best regards,
>>> Sylvain
>>>
>>>
>>> On Tue, Sep 4, 2018 at 5:09 AM Artem Sidyakin <artem.sidyakin at qt.io>
>>> wrote:
>>>
>>>> Have you succeeded? I got curious enough to try it myself and ran the
>>>> example in Xcode’s Simulator - it works (
>>>> https://i.imgur.com/bhE5NJa.png).
>>>> I don’t have free $99 to try it on an actual iOS device, but I guess it
>>>> will work fine there too.
>>>>
>>>> ---
>>>> Artem Sidyakin
>>>>
>>>> > On 29 Aug 2018, at 10:17, Artem Sidyakin <artem.sidyakin at qt.io>
>>>> wrote:
>>>> >
>>>> > Sure, I used this one:
>>>> https://github.com/retifrav/qml-webchannel-websockets/tree/master/websockets-mostly-qml/websockets
>>>> > And here’s an article about that just in case:
>>>> https://retifrav.github.io/blog/2018/07/14/html-from-qml-over-webchannel-websockets/#mostly-qml
>>>> >
>>>> > ---
>>>> > Artem Sidyakin
>>>> >
>>>> >> On 27 Aug 2018, at 00:21, Sylvain Pointeau <
>>>> sylvain.pointeau at gmail.com> wrote:
>>>> >>
>>>> >>
>>>> >> On Sun, 26 Aug 2018 at 19:47, Artem Sidyakin <artem.sidyakin at qt.io>
>>>> wrote:
>>>> >> I have an example working with Qt 5.11.1 on Mac OS and Android.
>>>> >> Unfortunately, I cannot check if it works on iOS - that’s why I was
>>>> guessing.
>>>> >>
>>>> >> could you put your example somewhere in github? so I can try it on
>>>> ios?
>>>> >>
>>>> >> Thank you
>>>> >>
>>>> >> Best regards,
>>>> >> Sylvain
>>>> >
>>>> > _______________________________________________
>>>> > Interest mailing list
>>>> > Interest at qt-project.org
>>>> > http://lists.qt-project.org/mailman/listinfo/interest
>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180914/f06d0dc4/attachment.html>


More information about the Interest mailing list