Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, April 2008
Hiding inherited property


Message 1 in thread

Hello everyone,

I've been playing with Qt's QObject Property mechanism for a while.
Browsing thru
the docs, I can't find any clues how to hide a property exposed by parent class
in the subclass.

For instance, I have the following class where i define one property...

class Specimen : public QObject{
 Q_OBJECT
 Q_PROPERTY(int lifetime READ getLifeTime)

  A(QObject* parent):QObject(parent){
  }
  ~A(){}
  int getLifeTime(){
    return lifeTime
  };


When i query the MetaObject for available properties I got two of them!!

// main
Speciment s(0);
MetaObject meta =  s.metaObject();
qDebug() << meta.propertyCount() ;     // prints 2

the other one's coming from QObject's 'name'.

Is there any way to 'hide' inherited properties such as that?
Does properties even gets 'inherited'?

Thx b4.

-- 
 [ signature omitted ] 

Message 2 in thread

Barkah Yusuf Widodo wrote:
>Speciment s(0);
>MetaObject meta =  s.metaObject();
>qDebug() << meta.propertyCount() ;     // prints 2
>
>the other one's coming from QObject's 'name'.
>
>Is there any way to 'hide' inherited properties such as that?

No. Even if you add another with the same name, you're still getting more 
properties.

>Does properties even gets 'inherited'?

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

On onsdag den 2. April 2008, Thiago Macieira wrote:
> Barkah Yusuf Widodo wrote:
> >Speciment s(0);
> >MetaObject meta =  s.metaObject();
> >qDebug() << meta.propertyCount() ;     // prints 2
> >
> >the other one's coming from QObject's 'name'.
> >
> >Is there any way to 'hide' inherited properties such as that?
>
> No. Even if you add another with the same name, you're still getting more
> properties.

And with good reason. You would break the object oriented nature of the 
objects, if this was possible.

The Right Way(TM) to hide base class details (methods, attributes, properties, 
etc.) in object oriented systems is to switch from subclassing to 
aggregation. Going from is-a to has-a solves the problem. But leaves others.

Bo.

-- 
 [ signature omitted ] 

Message 4 in thread

> Hello everyone,
> 
> I've been playing with Qt's QObject Property mechanism for a while.
> Browsing thru
> the docs, I can't find any clues how to hide a property exposed by
> parent class
> in the subclass.
> 
> For instance, I have the following class where i define one
property...
> 
> class Specimen : public QObject{
>  Q_OBJECT
>  Q_PROPERTY(int lifetime READ getLifeTime)
> 
>   A(QObject* parent):QObject(parent){
>   }
>   ~A(){}
>   int getLifeTime(){
>     return lifeTime
>   };
> 
> 
> When i query the MetaObject for available properties I got two of
> them!!
> 
> // main
> Speciment s(0);
> MetaObject meta =  s.metaObject();
> qDebug() << meta.propertyCount() ;     // prints 2
> 
> the other one's coming from QObject's 'name'.
> 
> Is there any way to 'hide' inherited properties such as that?
> Does properties even gets 'inherited'?
> 
> Thx b4.
> 

That's one of the big problems with meta based systems that don't allow
for private inheritance.

There is no way to hide the base classes slots either... Even if you
derive privately 

class Specimen : private QObject

or declare the slots private

private slots:
	void slotImASlot

Both the slot and properties of the base class might as well be
publically available.

Use the has-a relationship, but if your object still needs to be QObject
based, there is no way around this issue.

Scott


--
 [ signature omitted ] 

Message 5 in thread

I am actually creating a simple property editor sheet similar to thse in
GUI editors.  The initial idea was simply to let the editor introspect the
QObject via it's QMetaObject and expose the properties on a
QTableView.

Guess I have to go for something more sophisticated that that.

Thanks for the clarification.


On Thu, Apr 3, 2008 at 10:14 PM, Scott Aron Bloom
<Scott.Bloom@xxxxxxxxxxxx> wrote:
>
> > Hello everyone,
>  >
>  > I've been playing with Qt's QObject Property mechanism for a while.
>  > Browsing thru
>  > the docs, I can't find any clues how to hide a property exposed by
>  > parent class
>  > in the subclass.
>  >
>  > For instance, I have the following class where i define one
>  property...
>  >
>  > class Specimen : public QObject{
>  >  Q_OBJECT
>  >  Q_PROPERTY(int lifetime READ getLifeTime)
>  >
>  >   A(QObject* parent):QObject(parent){
>  >   }
>  >   ~A(){}
>  >   int getLifeTime(){
>  >     return lifeTime
>  >   };
>  >
>  >
>  > When i query the MetaObject for available properties I got two of
>  > them!!
>  >
>  > // main
>  > Speciment s(0);
>  > MetaObject meta =  s.metaObject();
>  > qDebug() << meta.propertyCount() ;     // prints 2
>  >
>  > the other one's coming from QObject's 'name'.
>  >
>  > Is there any way to 'hide' inherited properties such as that?
>  > Does properties even gets 'inherited'?
>  >
>  > Thx b4.
>  >
>
>  That's one of the big problems with meta based systems that don't allow
>  for private inheritance.
>
>  There is no way to hide the base classes slots either... Even if you
>  derive privately
>
>  class Specimen : private QObject
>
>  or declare the slots private
>
>  private slots:
>         void slotImASlot
>
>  Both the slot and properties of the base class might as well be
>  publically available.
>
>  Use the has-a relationship, but if your object still needs to be QObject
>  based, there is no way around this issue.
>
>  Scott
>
>
>



-- 
 [ signature omitted ] 

Message 6 in thread

On Thursday 03 April 2008 20:41:41 Barkah Yusuf Widodo wrote:
> I am actually creating a simple property editor sheet similar to thse in
> GUI editors.  The initial idea was simply to let the editor introspect the
> QObject via it's QMetaObject and expose the properties on a
> QTableView.
>
> Guess I have to go for something more sophisticated that that.

You can ignore properties that come from the parent in your view...

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.