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

Maxim maxim.bescherevnykh at gmail.com
Wed Mar 8 05:34:03 CET 2023

Maybe i did not cleary note at question: I placing all qml files related to
module (main.qml, Style.qml) into "qml" subdirectory (it was working
until i try to use singletons)
If i add ".qml" to the URI then QQmlApplicationEngine fails to load
component from either QUrl url1(u"qrc:/untitled/qml/main.qml"_qs),

qt_add_executable(untitled main.cpp )
set_source_files_properties(Style.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)

    URI untitled.qml
    VERSION 1.0

On Tue, Mar 7, 2023 at 2:55 PM Ulf Hermann via Interest <
interest at qt-project.org> wrote:

> > 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,
> Ulf
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230308/8e319aef/attachment.htm>

More information about the Interest mailing list