[Qt-interest] QObject::setProperty() not working on an inherited object with custom Enum

Girish Ramakrishnan girish at forwardbias.in
Tue Oct 13 06:58:05 CEST 2009


Hi,

Josiah Bryan wrote:
> Hey all -
> 
> Odd situation I ran into today. I've got a base object (AbstractItem),
> which inherits QObject. It defines a few Q_PROPERTY's of its own. An
> inherited class, AbstractVisualItem, also defines its own set of
> properties using the Q_PROPERTY macro. Now, the inherited class
> (A..VisualItem) defines a custom enum like 'typedef enum FillType { ...
> }', which is registered with Qt like:
> 
> Q_DECLARE_METATYPE(AbstractVisualItem::FillType);
> 
> And also registered in my main() function like:
> qRegisterMetaType<AbstractVisualItem::FillType>("FillType");
> 
> Now, the odd part is:
> 
> Say I've got a pointer to a base type, "AbstractItem *ptr", and I know
> its really a pointer a derived AbstractVisualItem object, so I call:
> 
> ptr->setProperty("fillType",AbstractVisualItem::Gradient);
> 
> (Remember, ptr is of the base class type A..I, not A..V..I, which A-V-I
> has the fillType property - but it should work anyway, right??)
> 

Yes, it is supposed to work.

> The problem is that setProperty() never calls
> AbstractVisualItem::setFillType(AbstractVisualItem::FillType), even
> though setFillType was given as the WRITE part of Q_PROPERTY:
> 
> Q_PROPERTY(FillType     fillType     READ fillType        WRITE
> setFillType);
> 
> Not sure why its not working - any ideas anyone?
> 

You need to add a Q_ENUMS(FillType).

Girish



More information about the Qt-interest-old mailing list