1
votes

ASAIK there is two way to create/import subfolders with QML :

  • Import with relatives path import "myQMLDir/mySubDir"
  • Import modules import myQMLDir.mySubDir 1.0 while you create qmldir files and add them to the import-path of the QtQuick engine.

The 1st one seems much simpler to do. The second one allows you to version your files or import them from external directories, but when you use them inside a project is it useful ?

1

1 Answers

2
votes

From my experience I would always go with the import MyModule 1.0 approach for the following examples:

  • Readability: import MyModule 1.0 is clearly simpler than a path-wise import. Example: import "../../../someDir/nextDir/myModule"
  • Refactoring: If you decide to move MyModule into another folder structure you have to change the import for all your js/qml files which use this import. You dont need to do this with the import MyModule 1.0 approach.
  • Private files: When you define the qmldir for your module you can define which qml/js files are included in it. With the relative path import all qml/js files are included.