There is a section in the docs explaining how "QML Modules":http://doc.qt.nokia.com/4.7/qdeclarativemodules.html import works and the two types of modules: location modules and installed modules.
This doc section worth reading, summing up what happens is:
- The current directory is by default part of the QML import path, that's why you don't need to import anything to use components defined in other files in the same directory;
- You can import components from a directory, importing the quoted relative or absolute path to it;
- Installed modules are imported using an URI relative to the path part of the QML_IMPORT_PATH variable.
Here is an example showing the use of these types of modules.
Consider the following tree:
The Test*.qml files are QML components. Due to my lack of creativity, I used rectangles with different colors. The most important is in main.qml.
import Qt 4.7
import "http://www.anselmolsm.org/public/qt/qml/remote_example" 1.0
import installed_modules 1.0
- Test1 is in the same directory, so it's part of the QML import path.
- Test2 is a location module, imported using the quoted relative path to its directory (Could be the absolute path).
- Test3 is an installed module and the version is required in the import line.
- RemoteTest is a location module as well, however it is not in the local filesystem.
If you run qmlviewer main.qml there will be an error because qmlviewer won't find installed_modules because it is not in the QML import path. To fix that, add "/path/to/example/dir" to QML_IMPORT_PATH (On Windows you can set it in the environment variables dialog).
Then, to solve:
[quote author="gri" date="1286808499"]
running "qmlviewer [path-to-qml-file]" leads to "LoginView is not a type"
adjust the code and app structure according to one of the possible ways.
PS: The example is available for download: "zip":http://anselmolsm.org/public/qt/qml/examples/qmlimport.zip or "tar.bz2":http://anselmolsm.org/public/qt/qml/examples/qmlimport.tar.bz2 . The remote component is available too.
Anselmo L. S. Melo (anselmolsm)