你可以在CPP的QML項指針下面的代碼
QQuickItem *項目= engine.rootObjects()第() - > 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);
}
通過其性質走在幾分鐘之內,你可以創建一個通用的用戶界面,讓這種方法修改任何對象的屬性,我想
我發現,如何在Qt創建器中完成:http://qt.gitorious.org/qt-creator/qt-creator/blobs/4eac04fba059a513bb58703660adf516cd6ce6ac/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp需要了解的是可能重用 – Dmitry