Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Singleton Additional Property Issue

Singleton Additional Property Issue

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml
7 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AdithyaA Offline
    AdithyaA Offline
    Adithya
    wrote on last edited by
    #1

    I am using Singleton file to have all the properties in a single file. So I have around 50+ properties in Styles.qml and it works.

    Issue:
    Whenever I keep adding new properties in Styles.qml I am getting some unusual issue .When I start using these properties I am getting "Unable to assign property"

    The code follows below :

    *****Styles.qml

    pragma Singleton
    import QtQuick 2.0

    Item{
    id:styleSheet

    //Login Dialog
    property string temp: "temp"
    property color mainwindowColor: "#cccccc"
    property color transparentColor: "transparent"
    property color whiteColor: "white"
    property color titleTextColor: "#00385F"
     .
     .
    

    }

    To make it Singleton I have used qmldir :
    singleton Styles 1.0 Styles.qml

    raven-worxR 1 Reply Last reply
    0
    • AdithyaA Adithya

      I am using Singleton file to have all the properties in a single file. So I have around 50+ properties in Styles.qml and it works.

      Issue:
      Whenever I keep adding new properties in Styles.qml I am getting some unusual issue .When I start using these properties I am getting "Unable to assign property"

      The code follows below :

      *****Styles.qml

      pragma Singleton
      import QtQuick 2.0

      Item{
      id:styleSheet

      //Login Dialog
      property string temp: "temp"
      property color mainwindowColor: "#cccccc"
      property color transparentColor: "transparent"
      property color whiteColor: "white"
      property color titleTextColor: "#00385F"
       .
       .
      

      }

      To make it Singleton I have used qmldir :
      singleton Styles 1.0 Styles.qml

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Adithya
      you say it works but still got an issue?
      What does working mean in this case then?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      AdithyaA 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @Adithya
        you say it works but still got an issue?
        What does working mean in this case then?

        AdithyaA Offline
        AdithyaA Offline
        Adithya
        wrote on last edited by
        #3

        @raven-worx Yes It is working but when I add new properties it starts giving some unusual errors

        Pradeep P NP 1 Reply Last reply
        0
        • AdithyaA Adithya

          @raven-worx Yes It is working but when I add new properties it starts giving some unusual errors

          Pradeep P NP Offline
          Pradeep P NP Offline
          Pradeep P N
          wrote on last edited by
          #4

          HI @Adithya
          What you mean by some unusual errors ?
          Can you provide clear details ?

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          AdithyaA 1 Reply Last reply
          1
          • Pradeep P NP Pradeep P N

            HI @Adithya
            What you mean by some unusual errors ?
            Can you provide clear details ?

            AdithyaA Offline
            AdithyaA Offline
            Adithya
            wrote on last edited by
            #5

            @Pradeep-P-N The old properties will stop working whenever I add new properties , I mean it will start showing errors such unable to assign color (This properties where working fine before but when I add new properties . It will start giving these errors)

            1 Reply Last reply
            0
            • Pradeep P NP Offline
              Pradeep P NP Offline
              Pradeep P N
              wrote on last edited by Pradeep P N
              #6

              Hi @Adithya
              It should work fine, independent of adding properties.

              Just check is you are following below sample

              • main.cpp :
                qmlRegisterSingletonType(QUrl(QSL("qrc:///qml/MyStyle.qml")), "AppStyles", 1, 0, "MyStyle");

              • MyStyle.qml replace Item {} with QtObject {}

                   pragma Singleton
              
                   import QtQuick 2.8
                   // import if you need any other 
               
                   QtObject {
                       // Add your own style properties here
                       // eg: readonly property bool on: true
                       // To use the style: import AppStyles 1.0
                       // Then: MyStyle.propertyName in other QML files
              
                        readonly property string temp: "temp"
                        readonly property color mainwindowColor: "#cccccc"
                       
                         - - - - - - 
                         - - - - - - 
              
                   }
              
              • Prefer using readonly property in the Style.qml

              All the best.

              Pradeep Nimbalkar.
              Upvote the answer(s) that helped you to solve the issue...
              Keep code clean.

              1 Reply Last reply
              3
              • Pradeep P NP Offline
                Pradeep P NP Offline
                Pradeep P N
                wrote on last edited by
                #7

                @Adithya

                Please if your issue is resolved, make it as SOLVED.

                Pradeep Nimbalkar.
                Upvote the answer(s) that helped you to solve the issue...
                Keep code clean.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved