Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] Reload a JS file at runtime (I'm testing ClojureScript as a workflow)
Forum Updated to NodeBB v4.3 + New Features

[solved] Reload a JS file at runtime (I'm testing ClojureScript as a workflow)

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 2.6k 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.
  • Q Offline
    Q Offline
    qttester5
    wrote on last edited by
    #1

    I am wondering if it is possible for a QML file to re-import a JS file while the Qt app is running? For example, the app is running, but you have an external JS editor that you are working in and when you save changes to a JS file, you want the QML to be able to recognize it without having to restart the entire Qt app. The standard "import" process at the top of a QML file would probably not be the best place for something like this. The best I can think of is to have the QML read a JS file dynamically and then call "eval()" on it. Thoughts?

    For anyone curious, I'm interested in have a dynamic development experience in Qt using ClojureScript outside of Qt to write the code that becomes JS, and then QML uses this JS. The translation to JS is certainly easy and works, but it's the constant lispy development workflow that I'm trying to emulate. Qt and QML are a great set of UI tools and it would be fun to access them in real-time through ClojureScript.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Right, you won't be able to use the import syntax, as the engine will parse and compile the import at import time, and cache the result for later use. Attempting to "re-import" it (via a dynamic Qt.createQmlObject() or similar which includes an import) will result in the cached compiled data being used.

      You will, however, be able to use Qt.include().
      So, probably the best way is to have a shim .js resource which has: "function reload() { Qt.include(fileName); /* now set global var values etc to whatever they need to be, based on the reloaded code which was included in this scope */ }"

      I haven't tested this personally, but cannot see why it wouldn't work.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qttester5
        wrote on last edited by
        #3

        Yes, that does work. I should have updated this question to note it was solved. I did some extensive experiments yesterday and arrived at the same conclusion. Thanks.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          violinwhl
          wrote on last edited by
          #4

          hello, qttester5 you said "I did some extensive experiments yesterday and arrived at the same conclusion." Could you tell me the another method which can get the same result?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chrisadams
            wrote on last edited by
            #5

            Note that there is a QQmlEngine::clearComponentCache() (or something) function. I'm fairly certain that that will only clear typedata for dynamically loaded QML types, not compiled JS units, but I may be wrong.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cpbotha
              wrote on last edited by
              #6

              [quote author="qttester5" date="1399359647"]Yes, that does work. I should have updated this question to note it was solved. I did some extensive experiments yesterday and arrived at the same conclusion. Thanks.[/quote]

              This is very interesting.

              Could you perhaps give some more detail about how your clojurescript -> qml setup works? Does this mean you can have arbitrary clojurescript generated javascript executed by the Qt V4VM js engine?

              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