Splitting a plugin into two qml files or more

• Dec 5, 2019 - 20:37

For readability reasons, I want to move a part of the plugin into another qml file. Is there an #include or a similar directive?


Comments

I believe it should be possible to use import myotherfile.js, but I'm not sure how the relative path would be resolved.

Basically, you should be able to do one of the following:

  • Extract some QML component into a separate .qml file and use that component in the "main" .qml file just by its name. If that separate .qml file is in the same directory that the QML file which uses it then no import statements are required at all. See the SquareButton example in Qt documentation.
  • Extract some functions to a separate .js file (say, utils.js) and put an import statement to the beginning of the file like
    import "utils.js" as Utils
    After that you should be able to use it in your QML file as
    var a = Utils.someFunction(b, c);

Do you still have an unanswered question? Please log in first to post your question.