I have a sample project at https://github.com/jh3010-qt-questions/qml_location
If my hierarchy looks like:
$ tree qml_location/
qml_location/
├── MyDeepComponent.qml
├── MyDeepComponentForm.ui.qml
├── main.cpp
├── main.qml
├── qml.qrc
└── qml_location.pro
Then I can write main.qml
like:
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
MyDeepComponent {}
}
and it will work.
However, I would like to organize some QML files into a folder hierarchy and not have them all at the same level.
For example, if I move to:
$ tree qml_location/
qml_location/
├── main.cpp
├── main.qml
├── qml
│ ├── MyDeepComponent.qml
│ ├── MyDeepComponentForm.ui.qml
│ └── more
│ ├── MyDeeperComponent.qml
│ └── MyDeeperComponentForm.ui.qml
├── qml.qrc
└── qml_location.pro
and have a main.qml
that looks like:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window
{
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Column
{
MyDeepComponent {}
MyDeeperComponent {}
}
}
Qt Creator tells me that MyDeepComponent and MyDeeperComponent are Unknown.
When I try to run, I get the error: MyDeepComponent is not a type
What can I do so this will work?
One caveat, I do not want to place a special or additional import at the top of main.qml. Is this still possible?
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>qml/MyDeepComponent.qml</file>
<file>qml/MyDeepComponentForm.ui.qml</file>
<file>qml/more/MyDeeperComponent.qml</file>
<file>qml/more/MyDeeperComponentForm.ui.qml</file>
</qresource>
</RCC>
qml_location.pro
QT += quick
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target