Consider if we want to support declaring QML files into the qmldir
Eg do we want to support writing the following for resources in QML modules
module ExampleModule
CustomButton 2.0 CustomButton20.qml
CustomButton 2.1 CustomButton21.qml
plugin examplemodule
MathFunctions 2.0 mathfuncs.js
https://doc.qt.io/qt-6/qtqml-modules-qmldir.html#example-of-a-qmldir-file
This basically allows you to then write
import QtQuick 2.0
import ExampleModule 2.1
Rectangle {
width: 400
height: 400
color: "lightsteelblue"
CustomButton {
color: "gray"
text: "Click Me!"
onClicked: MathFunctions.generateRandom() > 10 ? color = "red" : color = "gray";
}
}
In a CMake app this can be worked around by using a separate module, in a Cargo app this can happen to work if the QML file you are using is in the same "folder" as the component you are trying to use, but doesn't allow you to compartmentalise things.
Possible ways to solve this would be
- Automatically add all
.qml_filesand.qrc_filesby their file name into the qmldir - Have another field in the
QmlModulethat allows for custom lines like writingqmldir: &["CustomButton 2.0 CustomButton20.qml"] - Have some kind of map from url -> name + version
- ...
We should also consider what qt_add_qml_module supports in CMake https://doc.qt.io/qt-6/qt-add-qml-module.html
Seems there is https://doc.qt.io/qt-6/qt-target-qml-sources.html#source-file-properties
Looks like it uses
set_source_files_properties(FunnySingleton.qml PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)
...
set_source_files_properties(some_old_thing.qml PROPERTIES
QT_QML_SOURCE_VERSIONS "1.1;2.0"
QT_QML_SOURCE_TYPENAME OldThing
)
Which can then generate the following in a qmldir (although it's not clear where the File 2.0 File.qml comes from?)
File 2.0 File.qml
singleton FunnySingleton 2.0 FunnySingleton.qml
OldThing 1.1 some_old_thing.qml
OldThing 2.0 some_old_thing.qml
Maybe it's this (from https://doc.qt.io/qt-6/qt-target-qml-sources.html#source-file-properties )
By default, when generating the qmldir file, a single type entry will be generated for each .qml file that provides a type. It will be given a version number X.0 where X is the major version of the QML module. If the QML module has any PAST_MAJOR_VERSIONS set, the same pattern will be applied to those too, appending X.0 for each past major version X. For situations where a file needs to provide type entries for a different set of versions instead (e.g. it was first added in a minor patch version after the .0 release), specify those versions in the source file's QT_QML_SOURCE_VERSIONS property. One type entry will be created for each version.
Wonder how the "for each .qml file that provides a type" step works and if we could use that.
For now I'm using an additional field qmldir: Vec<(String, PathBuf)>, in OwningQmlModule:
qmldir: &[
("singleton Theme", "qml/Theme.qml"),
("Whitelist", "qml/Whitelist.js"),
("MyView", "qml/MyView.qml"),
],
Here are a singleton, a plain js file and a regular QML type.
Takes the version of the module and results in:
singleton Theme 1.0 qml/Theme.qml
Whitelist 1.0 qml/Whitelist.js
MyView 1.0 qml/MyView.qml