[Qt-interest] Q_PROPERTY confusion
Colin Kern
colin.kern at gmail.com
Mon Jun 22 01:58:42 CEST 2009
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
More information about the Qt-interest-old
mailing list