I think you may be looking for this:
https://doc.qt.io/qt-5/qtqml-modules-qmldir.html
Let's walk through their example code:
//Style.qml with custom singleton type definition
pragma Singleton
import QtQuick 2.0
QtObject {
property int textSize: 20
property color textColor: "green"
}
Above is our custom type we want to import into some other qml file.
// qmldir declaring the singleton type
module CustomStyles
singleton Style 1.0 Style.qml
Above is what we put into the qmldir file. You'll have to make a separate module and then that module will have this qmldir file. You'll have to make an empty file with the QtCreator wizard and name it to qmldir. This is a feature of Qt modules. You say, "this is the name of my module, and it has this type in it defined in Style.qml" inside that qmldir file. That's pretty much all it does. You can define as many qml types in there as you want.
// singleton type in use
import QtQuick 2.0
import CustomStyles 1.0
Text {
font.pixelSize: Style.textSize
color: Style.textColor
text: "Hello World"
}
Here we are importing the Style from our CustomStyles module, and using it where we want it.
So what is going on here is that
a module is created. A module is just a folder with a .pro file in it basically and a qmldir file. You will import your module with an import statement. You may want to use TEMPLATE = subdirs
to make a project with several modules.
Style.qml (just for example) is created and then exported (set to public) from that module. You set to public using the qmldir file in the module.
In the qml you want to import the qml file into you do
import CustomStyles 1.0
or whatever the module name you use in your project,
Then you can reference any QML type defined in the qmldir file because it has been set to public and you imported the module.
So instead of thinking about it like with c++ where you #include a file, think about it more like in python where you import a module and then you can reference any public class or func in that module.
Feel free to leave a comment if you want more clarification on how to create a module. You need to create a module because an import statement import modules not individual files. Importing a module gives access to all files exported from the module in the qmldir file.
StackLayout
andLoader
are direct QML ways to load other components. What exactly are you looking for? – JarMan