Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
5.8.0, 5.10.0
-
None
Description
Hi,
I'm trying to use Singletons in QML in order to overload a Style. And I don't know why my Singleton class destroys my value. Here is my snippet :
GenericTheme.qml
import QtQuick 2.0 QtObject { property var fonts: [] property QtObject fontFamily: QtObject { } onFontFamilyChanged: { for(var attr in fontFamily) { if(!(fontFamily[attr] instanceof Object)){ console.info(fontFamily[attr].length) if(fontFamily[attr].length > 0){ console.log("*" + fontFamily[attr] + "*") fonts.push(fontFamily[attr]); } } } fontsChanged() } function getFamily(weightId){ console.log(fonts[weightId]) return fonts[weightId] } }
My Singleton Theme.qml :
pragma Singleton import QtQuick 2.0 GenericTheme { fontFamily: QtObject { readonly property string light: "Style/Common/FONT/OpenSans-Light.ttf" readonly property string regular: "Style/Common/FONT/OpenSans-Regular.ttf" readonly property string semibold: "Style/Common/FONT/OpenSans-Semibold.ttf" readonly property string bold: "Style/Common/FONT/OpenSans-Bold.ttf" readonly property string extrabold: "Style/Common/FONT/OpenSans-ExtraBold.ttf" } Component.onCompleted: console.info(fonts.length) }
And my qmldir :
singleton Theme 1.0 Theme.qml
My fonts array gets all the values at the instanciation, but on the Component.onCompleted event the fonts array is empty ...
Have you got any tip ?
Thank you very much,
Olivier.
PS: I want to optimize the performances of my app.