Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Working with Q_PROPERTY and exposing the back end to the front end.



  • So when I create a variable and expose it to the front end like so:

            Q_PROPERTY(bool             connected                        READ connected                         WRITE setConnected              NOTIFY connectedChanged)
    
    

    I can call the setConnected from the front end or does it automatically get called when I call connected?



  • I believe the answer is that it calls that for me. For instance:

    object.connected = true
    

    is going to call the setConnected (setter) of the Q_PROPERTY. Whereas, saying something like:

    if(object.connected === true)
    

    is going to call connected (getter) of the Q_PROPERTY, correct? In other words, unless I plan on changing the value of connected from QML then I do not need a WRITE.

    Thanks for the correction @LeLev



  • hi

    @RobM said in Working with Q_PROPERTY and exposing the back end to the front end.:

    In other words, unless I plan on changing the value of connected from QML then I do not need a WRITE.

    yes that is correct, if you don't have the WRITE method then it will become like a read-only property


Log in to reply