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. [Solved]Create a read only property in qml
Forum Updated to NodeBB v4.3 + New Features

[Solved]Create a read only property in qml

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 7.8k Views 1 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.
  • S Offline
    S Offline
    stereomatching
    wrote on 9 Jul 2013, 02:06 last edited by
    #1

    //Whatever.qml
    @
    Rectangle{

    property string modelType: object.stringModel

    //.......
    }
    @

    What I want to do is, inside the Whatever.qml the modelType could be read or altered
    but for other's components modelType is a read only property

    Currently I am using function and QObject to hide the property
    Do pure qml have other choices for us?Thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on 9 Jul 2013, 06:18 last edited by
      #2

      In Qt Quick 2, you can actually declare readonly property like this:
      @readonly property string modelType: object.stringModel@
      In this case you would not be able to modify it after creation. If you need to modify it inside Whatever.qml you could instead create an internal property and declare a public readonly alias to it.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        stereomatching
        wrote on 9 Jul 2013, 06:57 last edited by
        #3

        Thanks for your helps

        1 Reply Last reply
        0

        1/3

        9 Jul 2013, 02:06

        • Login

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