Results 1 to 4 of 4

Thread: read-only property in qml

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default read-only property in qml

    Hello forum,

    I need a read-only property available in qml. Do I have to define a notify signal ? Consider the following scenario:

    Qt Code:
    1. Q_PROPERTY(float maxPatchVertices READ maxPatchVertices NOTIFY maxPatchVerticesChanged)
    To copy to clipboard, switch view to plain text mode 

    Above i need to retrive the value from the underlying C++ object and make it available to qml. Can i define the above snippet as follows instead:

    Qt Code:
    1. Q_PROPERTY(float maxPatchVertices READ maxPatchVertices)
    To copy to clipboard, switch view to plain text mode 


    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: read-only property in qml

    You need a NOTIFY signal if the value of the property can change during runtime, in order to allow the QML engine to update property bindings. This is independent of whether QML can write to the property.

    If the value can not change t all, then mark the property as CONSTANT.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: read-only property in qml

    The value never changes inside the QML. it is set once druing the opengl initialization and read in by one of the qt quick controls - slider maximumValue. When i assign value to the slider , i am getting 0. This is not correct. It seems that the Qt property system is getting initialized before the back-end opengl initialization

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: read-only property in qml

    Quote Originally Posted by sajis997 View Post
    The value never changes inside the QML. it is set once druing the opengl initialization and read in by one of the qt quick controls - slider maximumValue.
    Yes, you already wrote that it is a read-only property.
    It is even in the thread's title.

    Quote Originally Posted by sajis997 View Post
    When i assign value to the slider , i am getting 0. This is not correct. It seems that the Qt property system is getting initialized before the back-end opengl initialization
    The property system is not "initialized", see other thread.

    If you get 0 as the value of the property, then 0 is what the property's getter function returns. If that is not the right value, fix the getter function.

    Cheers,
    _

Similar Threads

  1. TypeError: Cannot read property 'length' of undefined in QML array
    By TheIndependentAquarius in forum Qt Quick
    Replies: 6
    Last Post: 12th June 2014, 06:39
  2. Replies: 1
    Last Post: 30th December 2013, 14:53
  3. Replies: 1
    Last Post: 1st July 2013, 14:27
  4. Technique to read file property details in Windows 7
    By astodolski in forum General Programming
    Replies: 3
    Last Post: 2nd March 2013, 08:37
  5. Exposing a Qt container property to QtScript, READ and WRITE
    By SingleMalt in forum Qt Programming
    Replies: 6
    Last Post: 12th May 2011, 07:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.