=================================================
// c++
=================================================
#includec++
#include
#include
#include
#include
#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("main.qml")); view.show(); QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect"); if (item) { item->setProperty("color", QColor(Qt::yellow)); } return app.exec(); } ==================================== // qml 界面顯示 main.qml =================================== import Qt 4.7 Item { width: 200; height: 200 Rectangle { anchors.fill: parent color: "red" objectName: "myRect" } }