Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML script provider similar to image provider
Forum Updated to NodeBB v4.3 + New Features

QML script provider similar to image provider

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 4.0k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    harchu
    wrote on last edited by
    #7

    Ok. but how do i make Qt/QML use this code to download the file? Can it be done via a plugin?
    I want to be able to use this custom code when someone writes:
    import "some-uri" as Remote
    At this point it should get the file using my plugin.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #8

      bq. but how do i make Qt/QML use this code to download the file?

      From C++ did you check the examples of QNetworkAccessManager::get ?

      You can call C++ functions from QML. Check "qtqml-cppintegration-topic":http://qt-project.org/doc/qt-5/qtqml-cppintegration-topic.html and especially "qtqml-cppintegration-exposecppattributes":http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html
      I'm not sure about the plugin as I have never used one.

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        harchu
        wrote on last edited by
        #9

        @p3c0: Thanks. I get how to use the QNetworkAccessManager to download the file. But I need to be able to run this code whenever someone uses the import statement for external javascript files. Sorry for not being clear before.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #10

          Well then check "registering-an-instantiable-object-type":http://qt-project.org/doc/qt-5/qtqml-cppintegration-definetypes.html#registering-an-instantiable-object-type. Create a Q_INVOKABLE function in it where you download the file then you can call this function from QML after instantiating it.

          157

          1 Reply Last reply
          0
          • H Offline
            H Offline
            harchu
            wrote on last edited by
            #11

            @p3c0: I am not able to get the example you stated above to work actually

            import "http://192.168.0.16/sample.js" as Remote

            I have my own node.js file server running on 8030 which i am trying to access using the below import statement:

            import "http://127.0.0.1:8030/testbrowser.js" as Browser

            Sometimes it does send a request to my server and my server correctly responds too, but the app then exits for some reason. do you know why that is?

            thanks,
            Rohit

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #12

              Sorry but i haven't used node.js. I have used it with particularly simple example like few JavaScript functions in sample.js and it works as expected.

              157

              1 Reply Last reply
              0
              • H Offline
                H Offline
                harchu
                wrote on last edited by
                #13

                Actually node.js is not the issue here..as the server does work when i try to access the file in the browser.
                Do you know why the download would not work in QML? My app exits with an exit code 255.
                Thanks

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #14

                  Can you try with some simple Javascript file which will contain just a few functions ?

                  157

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    harchu
                    wrote on last edited by
                    #15

                    i tried with an empty javascript file too and it did not seem to work

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #16

                      I tested it with apache server and it worked. The js file contains a simple function which returns a string.

                      sample.js
                      @
                      function myFunction() {
                      return "Hello Qt"
                      }
                      @

                      and the from QML
                      @
                      import "http://192.168.1.3/sample.js" as Remote
                      ...
                      //and on some Button click calling it as
                      Remote.myFunction()
                      @

                      157

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        harchu
                        wrote on last edited by
                        #17

                        It seems to work when I create a Qt Quick Application project from Qt Creator and try to import the javascript file from the node js server.

                        However the import fails when I create a Qt Quick UI project. Is there a way to enable this behavior in a Qt Quick UI project?

                        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