C
Importing QML document directories
A local directory of QML files can be imported without any additional setup or configuration.
Local directory imports
Any QML file on the local file system can import a local directory as using an import statement that refers to the directory's absolute or relative file system path, enabling the file to use the object types defined within that directory. The types will be made available with type names derived from the filenames of the QML documents. Only filenames beginning with an uppercase letter and ending with ".qml" will be exposed as types.
Directory imports rank below any module imports in precedence. If the same name is defined in a module and in a directory that are both imported into the same namespace, only the module's type is made available.
Directory import example
Consider the following QML project directory structure. Under the top level directory myapp, there are a set of common UI components in a sub-directory named mycomponents, and the main application code in a sub-directory named main, like this:
myapp
|- mycomponents
|- CheckBox.qml
|- DialogBox.qml
|- Slider.qml
|- main
|- application.qmlThe main/application.qml file can import the mycomponents directory using the relative path to that directory, allowing it to use the QML object types defined within that directory:
The directory may be imported into a qualified local namespace, in which case uses of any types provided in the directory must be qualified:
import "../mycomponents" as MyComponents MyComponents.DialogBox { // ... }
The ability to import a local directory is convenient for cases such as in-application component sets and application prototyping, although any code that imports such modules must update their relevant import statements if the module directory moves to another location. This can be avoided if QML modules are used instead, as an installed module is imported with a unique identifier string rather than a file system path.
Note: The QML files also have to be explicitly added to the application or module using the qmlproject file.
Implicit import
The directory in which a QML document resides is automatically imported. You do not have to explicitly import "." or similar.
Importing with auto loader (TO BE MODIFIED)
Auto loader can be used to import local directories as well:
auto/loader/SubPathLoading.qml:import "mysubdir" as MySubdir auto/loader/SubPathLoading.qml:import "mysubdir/mysubdir2" as MySubdir2
Once imported, you can use, for example, MySubdir.OrangeRect and MySubdir2.GreenRect. However, the QML files have to be explicitly listed in the qmlproject files under QmlFiles:
"mysubdir/OrangeRect.qml", "mysubdir/mysubdir2/GreenRect.qml",
Available under certain Qt licenses.
Find out more.