PDA

View Full Version : custom plugin designer property with out a variable?



high_flyer
15th March 2006, 19:44
Hi,

I made a custom designer plugin, which has a vector that holds various states.
But at design time (in designer) only the first element of the vector needs to be initilized.
Now, the Q_PROPERTY() macro needs a delcleration of a variable type and the variable name that holds the property (as far as I know), which forces me to declare an extra variable to receive the property value from designer, and then asign that variable in to the vector.
My question is, is there a way to assign the a value from the Q_PROPERTY() macro on to the vector without a intermidiate variable?

Thanks in advance.

jacek
15th March 2006, 20:11
Now, the Q_PROPERTY() macro needs a delcleration of a variable type and the variable name that holds the property (as far as I know), which forces me to declare an extra variable to receive the property value from designer, and then asign that variable in to the vector.
Q_PROPERTY works in a bit different way.

Suppose you have:
Q_PROPERTY( int x READ x WRITE setX )
This declares a property named "x" of int type. If Qt wants to assign a value for this property it will invoke the setX() method and when it wants to retrieve its value --- it will use the x() method. Qt doesn't know (and doesn't care) where do you actually store this property's value.

You can even write:
Q_PROPERTY( unsigned int size READ size )
//...
unsigned int size() const
{
return someDataStructure.size();
}