[Qt-interest] Q_PROPERTY confusion

Scott Aron Bloom Scott.Bloom at sabgroup.com
Mon Jun 22 04:03:00 CEST 2009


the

> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Colin Kern
> Sent: Sunday, June 21, 2009 4:59 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] Q_PROPERTY confusion
> 
> Hello,
> 
> I'm confused about using the Q_PROPERTY macro.  I've read the page in
> the documentation, and it gives this example:
> 
> class MyClass : public QObject
>  {
>      Q_OBJECT
>      Q_PROPERTY(Priority priority READ priority WRITE setPriority)
>      Q_ENUMS(Priority)
> 
>  public:
>      MyClass(QObject *parent = 0);
>      ~MyClass();
> 
>      enum Priority { High, Low, VeryHigh, VeryLow };
> 
>      void setPriority(Priority priority);
>      Priority priority() const;
>  };
> 
> One thing I notice is that both the member variable and the getter are
> called "priority".  Normally in C++, you get a naming collision if you
> try to make a member variable and member function the same name.  I
> notice, however, that the member variable isn't declared here.  The
> implementation of the getter and setter functions isn't given for this
> example, and I'm confused about how to write them.  If I try to do
> something like "this->priority = priority;" for the setter, or "return
> priority;" for the getter, I get errors indicating that the compiler
> thinks I am referring to the member function not the variable.  If I
> try to declare the Priority priority in the header file, I get errors
> about naming conflict as expected.  What is the proper way to do this?
> 
> Thanks,
> Colin Kern


------------
The name is NOT used as an actual object inside the class.. Its used by
the metaObject from TT..

It's the key to the mapping system used to lookup the properties.

Scott






More information about the Qt-interest-old mailing list