Reference error when accessing a QML singleton component
Unsolved
General and Desktop
-
Hi.
I'm creating a project with a singleton qml subcomponent.
pragma Singleton import QtQuick QtObject { property int windowWidth: 1280 property int windowHeight: 720 property string windowTitle: "SamplePlayer" }
This component should then be imported in the main QML component under the
Styles
namespace with theStyle
name.import QtQuick ... import Styles Window { width: Style.windowWidth height: Style.windowHeight title: Style.windowTitle ... }
I defined the qml subcomponent as a qml module in the build control file.
set_source_files_properties(Style.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) ... qt_add_qml_module( styles VERSION 1.0 URI Styles RESOURCE_PREFIX "/" PLUGIN_TARGET styles_plugin OUTPUT_DIRECTORY Styles QML_FILES Style.qml STATIC )
And linked the main executable against this module.
target_link_libraries( sample_media_player PRIVATE ... styles_plugin )
When I build and execute the program, the style properties defined in the qml subcomponent isn't applied. I get the following error messages in the console.
qrc:/Components/Main.qml:19: ReferenceError: Style is not defined qrc:/Components/Main.qml:17: ReferenceError: Style is not defined qrc:/Components/Main.qml:16: ReferenceError: Style is not defined
What's the reason of these errors? Why the properties defined in the qml singleton component isn't applied?
Thanks.
Project link
Building environments
Arch, CMake 3.29.3, Ninja 1.12.1, GCC 14.1.1, Qt 6.7.0
Debian 12.5, CMake 3.25, Ninja 1.11.1, GCC 12.2.0, Qt 6.4.2