您可以使用以下代码在 CPP 中获取 QML 项指针
QQuickItem *item = engine.rootObjects().first()->findChild("objectNameHere");
然后,您可以使用以下代码浏览其属性
for(int i=0;i<item->metaObject()->propertyCount();++i) {
// Here you can get the name of the property like
qDebug() << "Name" << item->metaObject()->property(i).name();
// Here you can get the type name of the property like
qDebug() << "Name" << item->metaObject()->property(i).typeName();
// Here you can check if it's a double type for example, and get the value and, set the value to ZERO again for example
if(item->metaObject()->property(i).type() == QVariant::DOUBLE) {
// Get the value
qDebug() << "Value" << item->property(item->metaObject()->property(i).name()).toDouble();
// Set the value to ZERO
item->setProperty(item->metaObject()->property(i).name(), 0.0);
}
在几分钟内,您可以创建一个通用 UI 来使用这种方法修改任何对象的属性,我猜