Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Macro Q_PROPERTY in child class

Macro Q_PROPERTY in child class

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views
  • 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.
  • Gianluca86G Offline
    Gianluca86G Offline
    Gianluca86
    wrote on last edited by
    #1

    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

    raven-worxR 1 Reply Last reply
    0
    • Gianluca86G Gianluca86

      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

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

      @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.

      --- 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

      1 Reply Last reply
      0
      • m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Gianluca86G Offline
          Gianluca86G Offline
          Gianluca86
          wrote on last edited by
          #4

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

          Thanks to both.

          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