class Test : public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
public:
Test(QObject *parent = 0) : QObject(parent) {}
virtual ~Test(){}
void setEnabled(bool e) { enabled = e; }
bool isEnabled() const { return enabled; }
private:
bool enabled;
};
然后在主函数中
Test *test = new Test;
test->setProperty("enabled", true);
//test->setEnabled(true); //ok also work
if(test->property("enabled").toBool())
.....
转载自:
http://blog.163.com/hu_cuit/blog/static/122849143201131255636442/