使用QMetaObject获取类的属性

const QMetaObject *metaobject = object->metaObject();
int count = metaobject->propertyCount();
for (int i = 0; i < count; ++i) {
    QMetaProperty metaproperty = metaobject->property(i);
    const char *name = metaproperty.name();
    QVariant value = object->property(name);
    qDebug() << name << value;
}

 

https://gitee.com/feiyangqingyun/qtkaifajingyan

posted @ 2019-10-08 22:36  findumars  Views(1243)  Comments(0Edit  收藏  举报