3

I collect some examples of import statement in QML. But one is lacking — import a qml file from js file.

Documentation says that it is a way to do it

.import Qt.test 1.0 as JsQtTest

but I can't make it work. I appreciate suggestions on my example collection and the answer to the question — how to import qml file from js file?

11
  • JsQtTest is not defined Commented Feb 24, 2015 at 11:25
  • It works for some other library? Commented Feb 24, 2015 at 11:27
  • No, I never succeed to import qml file from js Commented Feb 24, 2015 at 11:30
  • Which Qt/QML version? Commented Feb 24, 2015 at 11:32
  • Did you define "Qt.test" module? Commented Feb 24, 2015 at 12:01

1 Answer 1

1

One possible workaround for the issue I think is to do not import Qt library inside JS file but instead pass it as a parameter to the function exported from JS file:

function initLibrary(JsQtTest) {
   return {
      foo: function() {
         // use JsQtTest here
      }
   };
}

in QML you would write something like this:

import "myLibrary.js" as LibraryFactory
import Qt.test 1.0 as JsQtTest
...

var lib = LibraryFactory.initLibrary(JsQtTest)

lib.foo();
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thats the way I do it, but wanted to know more legal way. This is not a way if you want a js singleton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.