[Interest] QML singleton properties are undefined if file placed in subdirectory

Ulf Hermann ulf.hermann at qt.io
Tue Mar 7 12:54:21 CET 2023

> Qt 6.4.2 QML singleton's properties undefined if singleton QML file 
> placed in subdirectory e.g "/qml" (${CMAKE_SOURCE_DIR}/qml/Style.qml)

You should not place your QML files in a different directory than the 
module (as denoted by the generated qmldir file). Otherwise their 
implicit import is not the same as the module they belong to, which then 
leads to effects like this.

The implicit import is the way you can use QML components placed in .qml 
files in the same directory without importing anything.

The component in question is a singleton in the module since it has a 
"singleton" line in the qmldir. It is, however, a regular non-singleton 
component in the implicit import since the implicit import does not see 
the qmldir.

You can move the whole QML module into the "qml" subdirectory and add 
".qml" to the URI to avoid this. Or you can move all the .qml files into 
the base directory of the module.

best regards,

More information about the Interest mailing list