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

Josiah Bryan jbryan at productiveconcepts.com
Mon Oct 12 21:41:27 CEST 2009


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

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?

Thanks!
-josiah


-- 

-=-=-=-=-=-=-=-=-=-=-=-=-
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list