Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly
QtWS25 Last Chance

Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
10 Posts 4 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kuersat
    wrote on last edited by kuersat
    #1

    Hi guys,
    i want to have your thoughts and maybe a solution.
    What i am trying to do is, basically making it able to load qml files in a swipe view, if the qml file exists and run the .html in the browser.
    I thought it would be possible by just adding files without compiling again, but it isnt. I always need to run my Makefile again to get a new wasm file.
    Is there any option we could load qml dynamically without that procedure because it takes way to long to always run make again.
    Compiling time is about 5 minutes.
    I used the code from here https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
    Otherwise the app works perfectly fine.
    Just need to make sure i can load files by just adding file to the directory and not to qmake and make all again to get the wasm file. I know that the wasm file contains the compiled code but there s got to be a solution i think.

    Another thing is, maybe somebody knows because i tried to figure out and found some posts that didnt help, I cant use #include <QDeclarative>. It is possible and recommended to use Declarative for dynamic loadings via cpp.
    I checked my user/include and i verified that i had the necesarry files but still the same. I tried to add declarative in the .pro file but even that didnt help me out.

    Hoping to get help, thanks

    sierdzioS 1 Reply Last reply
    0
    • K kuersat

      Hi guys,
      i want to have your thoughts and maybe a solution.
      What i am trying to do is, basically making it able to load qml files in a swipe view, if the qml file exists and run the .html in the browser.
      I thought it would be possible by just adding files without compiling again, but it isnt. I always need to run my Makefile again to get a new wasm file.
      Is there any option we could load qml dynamically without that procedure because it takes way to long to always run make again.
      Compiling time is about 5 minutes.
      I used the code from here https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
      Otherwise the app works perfectly fine.
      Just need to make sure i can load files by just adding file to the directory and not to qmake and make all again to get the wasm file. I know that the wasm file contains the compiled code but there s got to be a solution i think.

      Another thing is, maybe somebody knows because i tried to figure out and found some posts that didnt help, I cant use #include <QDeclarative>. It is possible and recommended to use Declarative for dynamic loadings via cpp.
      I checked my user/include and i verified that i had the necesarry files but still the same. I tried to add declarative in the .pro file but even that didnt help me out.

      Hoping to get help, thanks

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @kuersat said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

      Just need to make sure i can load files by just adding file to the directory

      But your QML code directory is on server, right? Your WASM application runs on client side (in the web browser). So to load the files you need to specify the URL (and make sure that your server serves the files), then it should work (but make sure to use HTTP and not HTTPS, unless you want to fight with OpenSSL).

      I cant use #include <QDeclarative>

      That module is deprecated (it is the old QtQuick version 1). Use #include <QtQuick> and #include <QtQml> instead.

      (Z(:^

      thamT lorn.potterL 2 Replies Last reply
      6
      • sierdzioS sierdzio

        @kuersat said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

        Just need to make sure i can load files by just adding file to the directory

        But your QML code directory is on server, right? Your WASM application runs on client side (in the web browser). So to load the files you need to specify the URL (and make sure that your server serves the files), then it should work (but make sure to use HTTP and not HTTPS, unless you want to fight with OpenSSL).

        I cant use #include <QDeclarative>

        That module is deprecated (it is the old QtQuick version 1). Use #include <QtQuick> and #include <QtQml> instead.

        thamT Offline
        thamT Offline
        tham
        wrote on last edited by
        #3

        @sierdzio said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

        unless you want to fight with OpenSSL).

        Qt for webassembly do not support ssl yet, but we could use js to download the file, it works.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuersat
          wrote on last edited by
          #4

          sorry for answering late guys

          So i tried it again and i still cant get out of it, let me show u what i did.

          I have my basic main.qml which has a Swipe view and in the same file i have my javascript code:

          function fillItem(fileName){
          var component;
          var item;
          var request = new XMLHttpRequest()
          request.open('GET', fileName)
          request.onreadystatechange = function(event) {
          if (request.readyState === XMLHttpRequest.DONE) {
          console.log("File: ",fileName,"opened.");
          component = Qt.createComponent(fileName);
          item = component.createObject(firstPage,{});
          }
          }
          request.send()
          }
          --> It does well by loading the file and displaying what it should.
          --> After compiling to deploy in the browser, it works fine too. But now the thing I'd expect when I take the .qml File out which is loaded it should affect the swipe view so the page should not look the same like when the file was in the folder.

          @sierdzio Yes, i have everything on the server. Using the SimpleHTTPServer from python to run in the browser.
          I want it to load the file when the file is there and also try to load when the file is not there and display nothing because its not available or created.

          Thanks guys!

          1 Reply Last reply
          0
          • sierdzioS sierdzio

            @kuersat said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

            Just need to make sure i can load files by just adding file to the directory

            But your QML code directory is on server, right? Your WASM application runs on client side (in the web browser). So to load the files you need to specify the URL (and make sure that your server serves the files), then it should work (but make sure to use HTTP and not HTTPS, unless you want to fight with OpenSSL).

            I cant use #include <QDeclarative>

            That module is deprecated (it is the old QtQuick version 1). Use #include <QtQuick> and #include <QtQml> instead.

            lorn.potterL Offline
            lorn.potterL Offline
            lorn.potter
            wrote on last edited by
            #5

            @sierdzio said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

            @kuersat said in Trying to load qml files dynamically with javaScript in relation Qt for WebAssembly:

            Just need to make sure i can load files by just adding file to the directory

            But your QML code directory is on server, right? Your WASM application runs on client side (in the web browser). So to load the files you need to specify the URL (and make sure that your server serves the files), then it should work (but make sure to use HTTP and not HTTPS, unless you want to fight with OpenSSL).

            You should be able to use https anyway as we bypass Qt networking and use javascript to download.

            Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
            Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

            1 Reply Last reply
            1
            • lorn.potterL Offline
              lorn.potterL Offline
              lorn.potter
              wrote on last edited by lorn.potter
              #6

              wasm does not have direct access to local filesystems. You should be able to use network source for qml, if this does not currently work, there is a regression somewhere and you could kindly report a bug about it. :)

              MyComponent {
              source: "http://someserver/my.qml"
              }

              Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
              Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kuersat
                wrote on last edited by
                #7

                @lorn-potter actually i dont use the filesystem itself, i just upload the whole folder to the server.
                So it doesnt matter if http://... or qrc:/...
                still the same problem that i am not able to make changes once I comiled.

                Doesnt anyone have an Idea ?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kuersat
                  wrote on last edited by
                  #8

                  guys anyone?

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kuersat
                    wrote on last edited by
                    #9

                    *update
                    When using FileDialog the sandbox within the browser is opened so.
                    I think it does not make sense to manipulate the sandbox cause its gonna be changed anyways every time I start.
                    Also I found this bug report which is quite informative:
                    https://bugreports.qt.io/browse/QTBUG-67834

                    1 Reply Last reply
                    0
                    • lorn.potterL Offline
                      lorn.potterL Offline
                      lorn.potter
                      wrote on last edited by
                      #10

                      There is a way to 'persist' files, but you need to sync them from the local system into the sandbox.
                      https://emscripten.org/docs/api_reference/Filesystem-API.html

                      Using the IDBFS you can copy files to a mounted IndexDB filesystem.
                      In fact, QSettings on wasm uses this to attempt to persist QSettings.

                      Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
                      Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved