Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69504

QML Singleton on Custom type seems to destroy value

    XMLWordPrintable

Details

    • Windows

    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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            oliv-thales Olivier HENRY
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes