I'm new to Qt and came upon the Q_PROPERTY class, and was trying to set a static member using it. This is what I have so far:
class test{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
public:
bool enabled() const{
return m_enabled;
}
void setEnabled(bool enable){
m_enabled = enable;
}
private:
static bool m_enabled;
};
I'm getting compile errors when I try to run this so I'm not sure if there is a way to use static members with Q_PROPERTY. I've read through their documentation and other forum responses but I'm still unclear on the purpose of using Q_PROPERTY.
There's nothing special about using static members with Q_PROPERTY
. There are two problems with the code that you provided:
test
class does not derive from QObject
. Change it to this:class test: public QObject
Q_PROPERTY
. So in test.cpp, add this:bool test::m_enabled = false;
With those changes, it should compile just fine.