Macro Q_PROPERTY in child class



  • Hi everyone, I have a question about the macro "Q_PROPERTY".

    Example:

    class ClassA: public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int Width READ GetWidth WRITE SetWidth)
        Q_PROPERTY(int Height READ GetHeight WRITE SetHeight)
    ...
    }
    
    
    class SubClassA: public ClassA
    {
        Q_OBJECT
    ...
    }
    class SubClassB: public ClassA
    {
        Q_OBJECT
    ...
    }
    class SubClassC: public ClassA
    {
        Q_OBJECT
    ...
    }
    

    I know that the child classes inherit their father's property (so they will have the width and height properties).
    If I wanted the subclass C had as a property only the width, there is a way to "hide" the other property?

    These properties are displayed on a table.
    I hope I explained myself.
    Thank


  • Moderators

    @Gianluca86 said in Macro Q_PROPERTY in child class:

    If I wanted the subclass C had as a property only the width, there is a way to "hide" the other property?

    no, such feature doesn't exist yet.
    You can set the Q_PROPERTY to FINAL to mark it as non-overwritable.

    The presence of the FINAL attribute indicates that the property will not be overridden by a derived class. This can be used for performance optimizations in some cases, but is not enforced by moc. Care must be taken never to override a FINAL property.

    But this won't help you either.



  • Hi,
    you can put just the width property to the base class (ClassA) and add the height property in the sub classes (SubClassA and B) where they are needed.
    -Michael.



  • I understood, thanks.
    @m-sue : That's not a nice way, but I'll use it.

    Thanks to both.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.