QtObject singleton and Settings
-
I have some application wide settings stored in a
QtObjectsingleton object. I wanted to expose one of these as a persistent setting by extending an existingSettingsobject that I already use for main window size and position.GlobalSettings.qml in root qml directory:
pragma Singleton QtObject { property bool mySetting: false ... }main.qml in same directory:
... import "." ApplicationWindow { ... Settings { ... property alias mySetting: GlobalSettings.mySetting } }The application fails at startup with an error message:
Invalid alias reference. Unable to find id "GlobalSettings"Is the issue simply that it is not possible to alias a singleton property like this?
Is there an obvious way around this? I could introduce a boolean property in the
ApplicationWindowperhaps and alias that in theSettings, but the issue is that the boolean in question can be adjusted from a few places (menus and suchlike) and this is currently handled quite cleanly via the singleton. It would be awkward to route everything via a newApplicationWindowproperty. -
I have some application wide settings stored in a
QtObjectsingleton object. I wanted to expose one of these as a persistent setting by extending an existingSettingsobject that I already use for main window size and position.GlobalSettings.qml in root qml directory:
pragma Singleton QtObject { property bool mySetting: false ... }main.qml in same directory:
... import "." ApplicationWindow { ... Settings { ... property alias mySetting: GlobalSettings.mySetting } }The application fails at startup with an error message:
Invalid alias reference. Unable to find id "GlobalSettings"Is the issue simply that it is not possible to alias a singleton property like this?
Is there an obvious way around this? I could introduce a boolean property in the
ApplicationWindowperhaps and alias that in theSettings, but the issue is that the boolean in question can be adjusted from a few places (menus and suchlike) and this is currently handled quite cleanly via the singleton. It would be awkward to route everything via a newApplicationWindowproperty. -
@Bob64 did you put your GlobalSettings.qml in your CMakeLists.txt file?
set_source_files_properties( GlobalSettings.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE@mzimmers I am using qmake. Note that there is no problem in general in using my
GlobalSettingsobject - it has been in use for a couple of years. The problem is trying to persist one particular property in theGlobalSettingsQtObjectvia a property alias in mySettingsobject.Sorry I realise I should have chosen better names here. Just to be totally clear,
Settingsis a built in QML type that can be used to implement persistence of various application properties such as window sizes and so on.GlobalSettingsis the singletonQtObjectthat is specific to my application and contains various attributes that are queried throughout the application.The issue is that I have one specific property in
GlobalSettingsthat I also want to persist viaSettings. The standard way to do useSettingsis to add a property to it which is aproperty aliasto the actual value you want to persist. The reason it is not working for me is that theproperty aliasto theQtObjectproperty causes a run time error that aborts the application.