XMuli/QtExamples

in QtMeatObjectEx: the setProperty always return false

Closed this issue · 3 comments

image

it seems the setProperty do not work

m_girl->setProperty("sex", "Gril"); //动态属性
this line add a sex property, but onclassInfo do not print it

XMuli commented

“sex” 的属性是可以被打印出来的(点击 age 增加 Btn 或者 spinbox)
image

运行·如图
image

而你说说,没有被打印出来原因是 动态属性没有被 QObject::property() 给显示出来

QObject::setProperty() 函数可以在运行时为类定义一个新的属性,称之为动态属性。动态属性是针对类的实例定义的。

image

谢谢 了解了
QMetaObject是编译器由MOC生成的,所以QMetaObject无法知道动态属性
它是该类所有对象共享的,也就是一样的。
而动态属性是放入父类对象QObject中的
image
必须使用父类提供的property("sex")进行访问。