0

I have created a js file for storing constants inside assets/Model/constants.js I had a view inside assets/homeview.qml. This homeview.qml imports

import "Model/constants.js" as Global

and I could access Global.myConstant with no error.

Now I moved the homeview.qml inside a folder. assets/Views/homeview.qml and changed the import location to

import "/Model/constants.js" as Global

but now Global.myConstant shows unknown variable myConstant error. Is there something else I need to do when I move file inside a folder?

Francis F
  • 3,157
  • 3
  • 41
  • 79
  • it looks like you only added / before the path in you example. Also what exactli the file name - constant.js or constants.js? – folibis Feb 20 '15 at 07:52
  • file name is constants.js sorry for the typo in the question, yes I only added /, as when I moved the view to folder it showed error that import folder does not exist, adding / seemed to fix that. But I think the variables in the file still cant be accessed. Is there anything more I have to do? – Francis F Feb 20 '15 at 08:03

1 Answers1

0

Your import should work.

import "/Model/constants.js" as Global

Nevertheless, there is another way to import the file.

import "../Model/constants.js" as Global

This is a relative path to the file. At first you go one directory up and then go into the Model directory containing the constants.js file.

Oliver Kranz
  • 3,741
  • 2
  • 26
  • 31